Skip to content

fix: handle zero length slice data in JSON marshalling (fixes #1193) - #1315

Open
AruneshDwivedi wants to merge 1 commit into
cloudevents:mainfrom
AruneshDwivedi:fix/issue-1193-zero-length-slice
Open

fix: handle zero length slice data in JSON marshalling (fixes #1193)#1315
AruneshDwivedi wants to merge 1 commit into
cloudevents:mainfrom
AruneshDwivedi:fix/issue-1193-zero-length-slice

Conversation

@AruneshDwivedi

Copy link
Copy Markdown

Fixes #1193

When event has data that is a non-nil, zero length slice (empty byte slice), JSON marshalling produces malformed JSON with {"data":} which is invalid.

The fix checks for empty DataEncoded when mediaType is JSON and writes null instead of raw bytes.

Added test case that reproduces the issue and verifies the roundtrip (marshal -> unmarshal) works correctly.

@AruneshDwivedi
AruneshDwivedi requested a review from a team as a code owner August 9, 2026 10:00
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.

JSON marshalling produces invalid JSON when data is a zero length slice

1 participant