Repository navigation
Fix #343: Support Avro "single-object encoding" decoding with AvroReadFeature.READ_SINGLE_OBJECT_ENCODING - #905
Conversation
…ML#343) - Javadoc for READ_SINGLE_OBJECT_ENCODING: the schema used must be the exact writer schema (by Parsing Canonical Form), not just a compatible one - Cache writer fingerprint in a plain long + volatile flag instead of AtomicReference<Long> - Include original writer schema in Resolving.hashCode(), to match equals() Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One thing worth noting: the fingerprint check is strict. It compares against the Parsing Canonical Form of the writer schema, so a schema that is compatible but not identical fails. For example, a schema generated with This is probably what many users reading |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…L#343) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AvroReadFeature.READ_SINGLE_OBJECT_ENCODING) for Single Object Encoding
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AvroReadFeature.READ_SINGLE_OBJECT_ENCODING) for Single Object EncodingAvroReadFeature.READ_SINGLE_OBJECT_ENCODING
Fixes #343.
This adds
AvroReadFeature.READ_SINGLE_OBJECT_ENCODING. With it enabled, the parser reads the 10-byte Single Object Encoding header before each root-level value. That is the formatBinaryMessageEncoderwrites, and alsotoByteBuffer()of generated classes, which is what the issue ran into. Right now the header is read as content, so a record that starts with astringfails withInvalid length indicator for String: -98.The parser checks the header and fails with
StreamReadExceptionif the marker is not0xC3 0x01, or if the schema fingerprint does not match the writer schema. I left the feature disabled by default because the header can not be told apart from regular content. Anintof -98 is encoded as the same two bytes.One thing worth a look is the reader schema case.
withReaderSchema()applies the reader's aliases to the writer schema, which can change its fingerprint. SoResolvingnow keeps the writer schema as it was passed, and the fingerprint is taken from that. It is exposed asAvroSchema.getWriterFingerprint(), which is the only new public method.I moved the failing test out of
tofixand extended it. It runs with the native decoder and both Apache decoder modes, on values written byBinaryMessageEncoder, and also covers reader schemas with aliases, records with no fields, and bad or missing headers.Based on
3.xsince it is a new feature.clean verifyfor the Avro module passes on JDK 17 and 21.