avro icon indicating copy to clipboard operation
avro copied to clipboard

AVRO-3106: [java] Java JsonDecoder does not allow unknown fields in reader

Open gwallet opened this issue 3 months ago • 1 comments

The Java JsonDecoder does not actually allow there to be unknown fields in the reader compared to the writer's schema. In cases where this happens it gives the following error: org.apache.avro.AvroTypeException: Expected Unknown fields: []. Got END_OBJECT

What is the purpose of the change

This pull request makes the JsonDecoder allow unknown fields in the reader, fixing AVRO-3106.

Verifying this change

This change is already covered by existing tests, such as TestEncoders#jsonExcessFields. It has been adapted to reflect the change.

Documentation

  • Does this pull request introduce a new feature? no

gwallet avatar Sep 19 '25 16:09 gwallet

Hello! Thanks for your contribution -- I just want to clarify: the JsonDecoder does work if the writer schema and the reader schema are both present right? The test case only shows the reader schema.

RyanSkraba avatar Dec 04 '25 19:12 RyanSkraba

Hi!

The JsonDecoder is currently failing when a property is present in the JSON document that is not advertised by the reader schema.

It means that if a document producer send document relying on a new schema version which is backward compatible with the previous version (a new property/field), actual consumer that have not been updated can't read the document (at least the known properties advertised by the old document version schema).

That's why the testcase only shows the reader schema, because it is the relevant one that shows the 'old' version that should be able to read document with unknown properties, according to the statement:

if the writer's record contains a field with a name not present in the reader's record, the writer's value for that field is ignored.

gwallet avatar Dec 24 '25 11:12 gwallet