Skip to content

Fix empty maps inside slices unmarshalled as nil when field has omitempty#436

Open
SAY-5 wants to merge 1 commit into
mailru:masterfrom
SAY-5:fix/omitempty-propagation-in-element-decoders
Open

Fix empty maps inside slices unmarshalled as nil when field has omitempty#436
SAY-5 wants to merge 1 commit into
mailru:masterfrom
SAY-5:fix/omitempty-propagation-in-element-decoders

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 25, 2026

Copy link
Copy Markdown

When a struct field like []map[K]V is tagged omitempty, decoding [{}] produces a slice containing a nil map instead of an empty one. The field's omitempty tag was incorrectly forwarded to element decoders in slice, array, and map value generators, causing empty nested maps to be set to nil. Fixed by passing fieldTags{} to element type decoders. Adds the existing deepNestOptionalValue to testCases to cover round-trip unmarshal. Fixes #270.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

[{}] with omitempty incorrectly unmarshals into [nil] instead of [map]

1 participant