streamnative / pulsar-archived

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org
Apache License 2.0
73 stars 25 forks source link

ISSUE-3115: JSONSchema should works with generic (parameterized type) POJO/DTO. #197

Open sijie opened 4 years ago

sijie commented 4 years ago

Original Issue: apache/pulsar#3115


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)

congbobo184 commented 4 years ago

when PR https://github.com/apache/avro/pull/356 merge and pulsar update the avro version can solve the issue