Skip to content

feat(kafka)!: encode a record against its registered schema without registering - #44

Merged
sudoitir merged 7 commits into
mainfrom
claude/encode-against-a-registered-schema
Dec 3, 2026
Merged

sudoitir merged 7 commits into
mainfrom
claude/encode-against-a-registered-schema

Conversation

@sudoitir

@sudoitir sudoitir commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Summary

SchemaCatalog.encode used to derive a schema from the record's values and register it before framing, so producing a record had a side effect on the registry. This change makes encode a read-only operation against a schema that is already registered.

  • encode(String serdeName, String subject, EncodeOptions options, Map<String, ?> record) returns Encoded (bytes, schema id, subject, version, type, message name, whether the record was validated).
  • EncodeOptions: the subject's latest version or a named one, and for Protobuf the message to write (the first by default), with the message-index framing.
  • Avro and Protobuf are written against the registered schema; JSON Schema records are validated with com.networknt:json-schema-validator (its YAML reader excluded).
  • A record that does not fit is INVALID_ARGUMENT naming the field, not sent; an unknown subject or version is NOT_FOUND. Encode issues only reads to the registry.
  • Fix: a Protobuf schema with a package declaration could not be read.
  • ADR-0043 (amends ADR-0039); broker-sdk-kafka spec updated; OpenSpec change archived.

BREAKING CHANGE: the three-argument encode(serde, subject, record) is removed. Register the schema first with register(...) where the subject has none, then call encode(serde, subject, EncodeOptions.latest(), record).

Test plan

  • RegisteredEncodeTest (9), SchemaSerdeTest (5), SchemaRegistryNoteTest (3) locally
  • dependency convergence passes for the reactor
  • CI: build, unit tests, TCK, SchemaRoundTripIT (register, encode, decode back, version list unchanged), japicmp (break expected under 0.x)

🤖 Generated with Claude Code

sudoitir and others added 7 commits December 3, 2026 01:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egistering

Encoding reads the schema the subject already holds, its latest version or a named one, and writes the record with it. It no longer derives a schema from the values and registers it, so encoding changes nothing in the registry. A record that does not fit is refused as INVALID_ARGUMENT naming the field; an unknown subject or version is NOT_FOUND. Protobuf writes the named message (the first by default) with its message-index framing, JSON Schema records are validated, and a Protobuf schema that declares a package can now be read.

BREAKING CHANGE: SchemaCatalog.encode(serde, subject, record) is removed. Call encode(serde, subject, EncodeOptions.latest(), record), which returns Encoded (use bytes() for the payload). If the subject has no schema yet, register one first with register(...); encode no longer creates it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Registered schemas are JSON, and the YAML reader brought a snakeyaml-engine that diverged from
the one the Artemis driver brings, which failed the dependency-convergence rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…code accepts

A refusal no longer carries a map key or a value: map entries are shown as [], and a JSON Schema refusal is built from the failed rule and the field path instead of the validator's message. A Protobuf schema is read with the schema library's parser, so a package, qualified type names and comments mentioning a package all resolve. An Avro default fills only an absent field, an explicit null stays null, and a union branch of the value's own type wins. Protobuf unsigned and fixed-width integers take their full range, a record setting two fields of one oneof is refused naming both, whole BigInteger values are accepted where they fit, and an Avro decimal accepts a BigDecimal that fits its scale and precision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as a field name

A field the schema declares is named. One it does not declare is named only when it looks like an identifier, which keeps a typo useful; any other key, such as a card number or an address, shows as [] in Avro, Protobuf and JSON Schema refusals. An Avro union branch for a string now accepts any character sequence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
26 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@sudoitir
sudoitir merged commit 55842d2 into main Dec 3, 2026
21 of 22 checks passed
@sudoitir
sudoitir deleted the claude/encode-against-a-registered-schema branch December 3, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant