Skip to content

Accept omitzero as an alias of omitempty - #404

Open
AshSgDe29071999 wants to merge 1 commit into
yaml:mainfrom
AshSgDe29071999:fix/omitzero-tag
Open

AshSgDe29071999 wants to merge 1 commit into
yaml:mainfrom
AshSgDe29071999:fix/omitzero-tag

Conversation

@AshSgDe29071999

@AshSgDe29071999 AshSgDe29071999 commented Aug 25, 2026

Copy link
Copy Markdown

Go 1.24 added omitzero for encoding/json. getStructInfo only knows omitempty, flow, and inline, so a struct that shares tags with json panics in mappingStruct:

panic: unsupported flag "omitzero" in tag "...,omitzero"

This library's omitempty already drops zero values (including structs), so treat omitzero as the same flag.

This is the same failure as the archived v3 tree (go-yaml/yaml#1068).


Maintainers' edits to the PR description 👇

Somehow related to #235

Go 1.24's encoding/json flag omitzero panics getStructInfo, which only
knows omitempty/flow/inline. yaml's omitempty already drops zero values,
so treat omitzero as the same so structs that share tags with json work.

Related: go-yaml/yaml#1068 (archived v3 tree).
@ccoVeille

Copy link
Copy Markdown
Contributor

This would require further checks.

encoding/json omitzero is not omitempty

yaml/go-yaml omitempty might behave the same way for struct (I have to check) that encoding/json handles omitzero

But then I'm unsure yaml/go-yaml should handle omitzero the same way for non-struct

So it might not be about aliasing. Maybe it's more about handing omitzero the same way that omitempty for struct only.

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.

2 participants