Skip to content

Fix #343: Support Avro "single-object encoding" decoding with AvroReadFeature.READ_SINGLE_OBJECT_ENCODING - #905

Merged
cowtowncoder merged 10 commits into
FasterXML:3.xfrom
Vineet829:vineet829/3.x/343-avro-single-object-encoding
Nov 30, 2026
Merged

cowtowncoder merged 10 commits into
FasterXML:3.xfrom
Vineet829:vineet829/3.x/343-avro-single-object-encoding

Conversation

@Vineet829

Copy link
Copy Markdown
Contributor

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 format BinaryMessageEncoder writes, and also toByteBuffer() of generated classes, which is what the issue ran into. Right now the header is read as content, so a record that starts with a string fails with Invalid length indicator for String: -98.

The parser checks the header and fails with StreamReadException if the marker is not 0xC3 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. An int of -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. So Resolving now keeps the writer schema as it was passed, and the fingerprint is taken from that. It is exposed as AvroSchema.getWriterFingerprint(), which is the only new public method.

I moved the failing test out of tofix and extended it. It runs with the native decoder and both Apache decoder modes, on values written by BinaryMessageEncoder, and also covers reader schemas with aliases, records with no fields, and bad or missing headers.

Based on 3.x since it is a new feature. clean verify for the Avro module passes on JDK 17 and 21.

@cowtowncoder cowtowncoder added avro cla-received Marker to denote that there is a CLA for pr labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage Report

Coverage Type Coverage Change
📝 Instructions 80.84% 📈 +0.10%
🔀 Branches 75.40% 📈 +0.18%

Vineet829 and others added 5 commits November 18, 2026 13:14
…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>
@cowtowncoder

Copy link
Copy Markdown
Member

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 AvroMapper.schemaFor() that differs from the writer schema only in the name or namespace of a record will be rejected, even though the content itself would decode fine.

This is probably what many users reading toByteBuffer() output of Avro-generated classes with Jackson-generated schemas will run into. It is documented in the Javadoc and README, so I think it's fine as the default. But we may want to add an option later that verifies only the marker bytes (or skips header verification completely). Something to consider as a follow-up rather than for this PR.

cowtowncoder and others added 2 commits November 29, 2026 17:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…L#343)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cowtowncoder cowtowncoder changed the title Fix #343: add Avro read feature for Single Object Encoding Fix #343: add Avro read feature (AvroReadFeature.READ_SINGLE_OBJECT_ENCODING) for Single Object Encoding Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cowtowncoder cowtowncoder changed the title Fix #343: add Avro read feature (AvroReadFeature.READ_SINGLE_OBJECT_ENCODING) for Single Object Encoding Fix #343: Support Avro "single-object encoding" decoding with AvroReadFeature.READ_SINGLE_OBJECT_ENCODING Nov 30, 2026
@cowtowncoder cowtowncoder added this to the 3.4.0 milestone Nov 30, 2026
@cowtowncoder
cowtowncoder merged commit fc173b5 into FasterXML:3.x Nov 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

avro cla-received Marker to denote that there is a CLA for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Avro "single-object encoding" decoding with AvroReadFeature.READ_SINGLE_OBJECT_ENCODING

2 participants