You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/27 02:21:14 UTC

[GitHub] [pulsar] linlinnn opened a new issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

linlinnn opened a new issue #10393:
URL: https://github.com/apache/pulsar/issues/10393


   Related #10377
   
   **Is your enhancement request related to a problem? Please describe.**
   Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.
   
   Reproduce code
   ```
   @Data
   @AllArgsConstructor
   public static class Payload {
       String message;
   }
   
   public static void main(String[] args) {
       AvroSchema<Payload> schema = AvroSchema.of(Payload.class);
       Payload payload = new Payload("test");
       byte[] encode = schema.encode(payload);
       schema.decode(encode);
   }
   ```
   
   Exception stack
   ```
   Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.pulsar.client.impl.schema.JSONSchema$Payload.<init>()
   	at org.apache.avro.specific.SpecificData.newInstance(SpecificData.java:466)
   	at org.apache.avro.specific.SpecificData.newRecord(SpecificData.java:484)
   	at org.apache.avro.reflect.ReflectData.newRecord(ReflectData.java:1038)
   	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:236)
   	at org.apache.avro.specific.SpecificDatumReader.readRecord(SpecificDatumReader.java:123)
   	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
   	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:160)
   	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
   	at org.apache.pulsar.client.impl.schema.reader.AvroReader.read(AvroReader.java:75)
   	at org.apache.pulsar.client.api.schema.SchemaReader.read(SchemaReader.java:39)
   	at org.apache.pulsar.client.impl.schema.reader.AbstractMultiVersionReader.read(AbstractMultiVersionReader.java:62)
   	at org.apache.pulsar.client.api.schema.SchemaReader.read(SchemaReader.java:39)
   	at org.apache.pulsar.client.impl.schema.AbstractStructSchema.decode(AbstractStructSchema.java:55)
   	at org.apache.pulsar.client.impl.schema.JSONSchema.main(JSONSchema.java:75)
   Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.pulsar.client.impl.schema.JSONSchema$Payload.<init>()
   	at org.apache.avro.specific.SpecificData$1.computeValue(SpecificData.java:67)
   	at org.apache.avro.specific.SpecificData$1.computeValue(SpecificData.java:58)
   	at java.lang.ClassValue.getFromHashMap(ClassValue.java:227)
   	at java.lang.ClassValue.getFromBackup(ClassValue.java:209)
   	at java.lang.ClassValue.get(ClassValue.java:115)
   	at org.apache.avro.specific.SpecificData.newInstance(SpecificData.java:463)
   	... 13 more
   Caused by: java.lang.NoSuchMethodException: org.apache.pulsar.client.impl.schema.JSONSchema$Payload.<init>()
   	at java.lang.Class.getConstructor0(Class.java:3082)
   	at java.lang.Class.getDeclaredConstructor(Class.java:2178)
   	at org.apache.avro.specific.SpecificData$1.computeValue(SpecificData.java:63)
   	... 18 more
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #10393:
URL: https://github.com/apache/pulsar/issues/10393#issuecomment-827324098


   I am not sure we can do something here.
   We should open a ticket in Avro and in Jackson Mapper libraries.
   
   If we add too much 'magic' we could introduce some new behaviour that diverges from the downstream libraries and it will be very hard to maintain.
   In java parameters are set by position and not by name so there is no way we can decide which constructor to use and the order of parameters.
   
   We could say we will support Java Records, but that's another story and also it should be handled by the deserialization library as well


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] linlinnn commented on issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

Posted by GitBox <gi...@apache.org>.
linlinnn commented on issue #10393:
URL: https://github.com/apache/pulsar/issues/10393#issuecomment-827266011


   @eolivelli Please take a look


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] linlinnn closed issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

Posted by GitBox <gi...@apache.org>.
linlinnn closed issue #10393:
URL: https://github.com/apache/pulsar/issues/10393


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] linlinnn edited a comment on issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

Posted by GitBox <gi...@apache.org>.
linlinnn edited a comment on issue #10393:
URL: https://github.com/apache/pulsar/issues/10393#issuecomment-827328360


   @eolivelli 
   I agree with you, so maybe we should hint user to add default constructor when using struct schema, otherwise they will be confused about send message sucessfully but receive message cannot decode.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] linlinnn commented on issue #10393: Struct schema(AvroSchema/JSONSchema) cannot decode without default constructor.

Posted by GitBox <gi...@apache.org>.
linlinnn commented on issue #10393:
URL: https://github.com/apache/pulsar/issues/10393#issuecomment-827328360


   @eolivelli 
   I agree with you, so maybe we should hint user to add default construct when using struct schema, otherwise they will be confused about send message sucessfully but receive message cannot decode.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org