Skip to content

story(issue-73): add JSON serde to kafka Client Produce/Consume#77

Merged
Zaba505 merged 2 commits into
mainfrom
worktree-issue-73
May 20, 2026
Merged

story(issue-73): add JSON serde to kafka Client Produce/Consume#77
Zaba505 merged 2 commits into
mainfrom
worktree-issue-73

Conversation

@Zaba505
Copy link
Copy Markdown
Member

@Zaba505 Zaba505 commented May 20, 2026

Summary

  • Adds keySerializeAs / valueSerializeAs to *Client.Produce and keyDeserializeAs / valueDeserializeAs to *Client.Consume. "JSON" is the only non-empty value accepted; default "" is pass-through.
  • Produce canonicalises via encoding/json (parse + re-marshal) before framing — invalid JSON is rejected before any broker I/O. Consume validates via json.Valid after frame strip.
  • Composes with the existing valueSchemaID / schemaRegistryAware opts so a single call can both frame and validate. No new dependencies — encoding/json only.

Closes #73.

Test plan

  • dagger develop in daggerverse/kafka/ and daggerverse/kafka/tests/
  • dagger -m daggerverse/kafka/tests call schema-registry-jsonserialize-rejects-malformed-input (negative, no broker — 13s)
  • dagger -m daggerverse/kafka/tests call schema-registry-jsonframed-produce-consume-round-trip --kafka-image-tag=4.2.0 (SR+JSON round-trip, asserts byte-equality against canonical form — 23s)
  • dagger -m daggerverse/kafka/tests call all --parallel=4

🤖 Generated with Claude Code

Layers JSON wire-format enforcement on top of the Confluent framing
primitive from #42: Produce canonicalises via encoding/json before
framing; Consume validates via json.Valid after frame strip. Defaults
are pass-through so existing callers are unaffected.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Zaba505 Zaba505 self-assigned this May 20, 2026
@Zaba505 Zaba505 added the enhancement New feature or request label May 20, 2026
@Zaba505 Zaba505 requested a review from Copilot May 20, 2026 22:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the daggerverse/kafka Dagger module’s Client.Produce / Client.Consume APIs with optional JSON wire-format enforcement, allowing callers to canonicalize JSON before producing and validate JSON after consuming, while composing cleanly with existing Confluent Schema Registry framing options.

Changes:

  • Add keySerializeAs / valueSerializeAs to Client.Produce and keyDeserializeAs / valueDeserializeAs to Client.Consume, supporting "" (pass-through) and "JSON".
  • Implement JSON canonicalization on produce (parse + re-marshal) and JSON validation on consume (json.Valid).
  • Add schema-registry-focused tests for malformed JSON rejection and framed JSON round-trip; document the new options and composition order in the README.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
daggerverse/kafka/client.go Adds JSON serialize/deserialize modes and integrates them into Produce/Consume pipelines.
daggerverse/kafka/README.md Documents JSON serde options and how they compose with Schema Registry framing.
daggerverse/kafka/tests/tests_schema_registry.go Adds tests for malformed JSON rejection and framed JSON round-trip with canonicalization.
daggerverse/kafka/tests/main.go Registers the new schema-registry JSON serde tests in the schema registry test group.

Comment thread daggerverse/kafka/client.go Outdated
Copilot review on #77 flagged two payload-mutation bugs in canonicalJSON:
json.Unmarshal into any decodes numbers as float64 (silently losing
precision above 2^53), and json.Marshal HTML-escapes <, >, & in
strings. Both violate the "canonicalise without corrupting payload"
intent.

Switch to json.Decoder with UseNumber() so large integers and
high-precision decimals round-trip as json.Number, and use json.Encoder
with SetEscapeHTML(false) so string contents pass through verbatim.
Also reject trailing tokens after the first JSON value so callers can't
smuggle extra documents through the validator.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread daggerverse/kafka/client.go
@Zaba505 Zaba505 merged commit 863ed80 into main May 20, 2026
5 of 6 checks passed
@Zaba505 Zaba505 deleted the worktree-issue-73 branch May 20, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

story(daggerverse): JSON serde on kafka Client Produce/Consume

2 participants