question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONSchema should works with generic (parameterized type) POJO/DTO.

See original GitHub issue

Expected behavior

JSONSchema should works with generic (parameterized type) POJO/DTO. No exception at runtime, or at least update documentation/errorMessage how to work-around/bypass the issue.

Actual behavior

Exception when running producer/consumer with JSONSchema.of(clazz) (or Schema.JSON(clazz) ) wiith generic/parameterized class:

Exception in thread "main" java.lang.NoSuchFieldError: KEY_VALUE
	at org.apache.pulsar.client.impl.schema.KeyValueSchema.<init>(KeyValueSchema.java:50)
	at org.apache.pulsar.client.api.Schema.<clinit>(Schema.java:128)

Steps to reproduce

Create Producer or Consumer with client API, using JSONSchema.of(clazz) (or Schema.JSON(clazz) ) wiith generic/parameterized class. Compiled OK, but when running the client producer/consumer it throws exception.

Example (https://github.com/ducquoc/pulsar/commit/a0649dc8): https://github.com/ducquoc/pulsar/blob/fix-client-schema_json-schema-generic-parameterized-type/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/pojo/BrokerMessage.java

** Work-around: use

private Object payload;

and respective getter/setter instead of

private T payload;

System configuration

Pulsar version: 2.2.0 (but seems to be also affected on latest master branch)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rohts-patilcommented, Nov 29, 2019

@vamsi360 ,

I cloned your fork and built it to version 1.8.3-ppe-9.10. I still get the errror.

Caused by: org.apache.avro.AvroTypeException: Unknown type: T
	at org.apache.avro.specific.SpecificData.createSchema(SpecificData.java:312)
	at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:720)
	at org.apache.avro.reflect.ReflectData.createFieldSchema(ReflectData.java:870)
	at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:686)
	at org.apache.avro.specific.SpecificData$2.load(SpecificData.java:238)
	at org.apache.avro.specific.SpecificData$2.load(SpecificData.java:235)
	at avro.shaded.com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3568)
	at avro.shaded.com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2350)
	at avro.shaded.com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2313)
	at avro.shaded.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2228)
	... 6 more
1reaction
frankjkellycommented, Sep 8, 2020

We too have been hit by this issue trying to send generics

public class InteractionEvent<T>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Dynamic References to Support Generic Types
The topic in this post can apply to any programming paradigm where you have a defined data model and support for something like...
Read more >
dev - The Mail Archive
[GitHub] [pulsar] ducquoc created a discussion: JSONSchema should works with generic (parameterized type) POJO/DTO. GitBox.
Read more >
jsonschema - Json generic object type - Stack Overflow
It is possible to do something like that using json-schema but you need to define the schemas, take a look to this samples:....
Read more >
Model | Ts.ED - A Node.js and TypeScript Framework on top of ...
The Model will generate a JsonSchema which can be used by modules ... we can use it inside a Controller as input type...
Read more >
JsonSchema (API Discovery Service v1 (Rev. 134) 1.25.0)
public final class JsonSchema extends com.google.api.client.json.GenericJson ... The regular expression this parameter must conform to. java.util.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found