steven-aerts commented on PR #3373: URL: https://github.com/apache/avro/pull/3373#issuecomment-2854927666
@KalleOlaviNiemitalo the ambiguity you describe is contained in [AVRO-2287](https://issues.apache.org/jira/browse/AVRO-2287). What we are seeing is that the C library goes for the _name_ interpretation and the java library goes for the _fullname_ description. To reproduce this with an example, I used the schema at the bottom of this message. To encode: * `avro_value_to_json` will output `{"field": {"r2": {}}}`. * While the `JsonEncoder` outputs `{"field": {"space.r2": {}}}`. On the decoding side: C does not have a implementation for decoding the json encoding. However when you try with java to to read `{"field": {"r2": {}}}` with the `JsonDecoder` for this schema you get: ``` Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union branch r2 at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:434) at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:282) at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:188) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161) at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:260) at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:248) at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:180) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161) ``` Which shows the implementation differences for both languages. And java is clearly expecting a fully qualified path for enums. This patch proposes to line up the behavior for C with that of Java. Would you prefer the other way around? Are you willing to accept a patch on the Java side which allows reading the C encoding? Example schema: ``` { "type": "record", "name": "r", "fields": [ { "name": "field", "type": [ "null", { "type": "record", "name": "r2", "namespace": "space", "fields": [] } ] } ] } ``` Java code use to generate exception: ``` var decoder = DecoderFactory.get().jsonDecoder(schema, "{\"field\": {\"r2\": {}}}"); var data = new GenericDatumReader(schema).read(null, decoder); ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
