fix(encoding): generate transitive MarshalJSON for wrapper messages with int64_encoding=NUMBER nested fields#125
Merged
SebastienMelki merged 5 commits intomainfrom Mar 2, 2026
Conversation
🔍 CI Pipeline Status✅ Lint: success 📊 Coverage Report: Available in checks above |
…ing in wrapper responses Add SensorReading (inner, direct NUMBER fields) and GetSensorReadingResponse/GetMultiSensorResponse (wrapper messages) test proto. Golden files for both httpgen and clientgen cover the new cases. Test cases added to both golden_test.go files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…th nested NUMBER fields When a wrapper/response message contains a field whose type has int64_encoding=NUMBER fields, protojson.Marshal bypasses the inner message's MarshalJSON — producing strings instead of numbers. Fix adds a two-phase collection in generateInt64EncodingFile: - Phase 1 (existing): collect messages with direct NUMBER fields - Phase 2 (new): collect wrapper messages whose fields reference phase-1 types Wrapper messages get generated MarshalJSON/UnmarshalJSON that use protojson for base serialization, then re-marshal each nested NUMBER field via json.Marshal to trigger the inner message's custom MarshalJSON. Closes #124 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…with nested NUMBER fields Identical fix to httpgen: two-phase collection detects wrapper messages containing fields whose type has int64_encoding=NUMBER, generating MarshalJSON/UnmarshalJSON that re-marshal those nested fields via json.Marshal to trigger the inner message's custom marshaling. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…coding.go golangci-lint (golines) flagged collectWrapperMessages and two gf.P() calls in generateWrapperMarshalJSON/UnmarshalJSON for exceeding the line length limit. Auto-fixed with golangci-lint --fix; golden files regenerated to match. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3f3b2f5 to
e8e52a6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #125 +/- ##
========================================
- Coverage 3.17% 3.09% -0.09%
========================================
Files 47 47
Lines 7485 7701 +216
========================================
Hits 238 238
- Misses 7243 7459 +216
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SebastienMelki
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where response/wrapper messages containing nested messages with
int64_encoding=NUMBERfields had their int64 values serialized as strings instead of JSON numbers.marshalResponsechecks forjson.Marshalerbefore dispatching — only the inner message hadMarshalJSON()generated, not the outer wrapperprotojson.Marshal(the fallback) uses protobuf reflection and never callsjson.Marshalermethods on nested messageshttpgenandclientgenhad the identical gapRoot cause
collectInt64EncodingMessagesonly generatedMarshalJSON()for messages with direct NUMBER fields. Wrapper messages that merely referenced such types were not detected.Fix
Two-phase collection in
generateInt64EncodingFile:MarshalJSON/UnmarshalJSONthat useprotojson.Marshalfor base serialization, then re-marshal each nested field viajson.Marshal— triggering the inner message's custom methodChanges
internal/httpgen/encoding.go— addedInt64WrapperContext,collectWrapperContexts,collectWrapperMessages,generateWrapperMarshalJSON,generateWrapperUnmarshalJSONinternal/clientgen/encoding.go— identical fixinternal/httpgen/testdata/proto/int64_nested_encoding.proto— new test proto withSensorReading(inner, NUMBER fields) andGetSensorReadingResponse/GetMultiSensorResponse(wrappers)internal/clientgen/testdata/proto/int64_nested_encoding.proto— symlink to aboveTest plan
go test -run TestHTTPGenGoldenFiles ./internal/httpgen— PASS (13 cases)go test -run TestClientGenGoldenFiles ./internal/clientgen— PASS (14 cases)./scripts/run_tests.sh --fast— all relevant packages PASSint64_nested_encoding_encoding.pb.gocontainsMarshalJSON/UnmarshalJSONforSensorReading,GetSensorReadingResponse, andGetMultiSensorResponseCloses #124
🤖 Generated with Claude Code