Skip to content

Add support for omitzero struct tag#415

Open
mwoss wants to merge 3 commits intomasterfrom
omitzero-tag
Open

Add support for omitzero struct tag#415
mwoss wants to merge 3 commits intomasterfrom
omitzero-tag

Conversation

@mwoss
Copy link
Member

@mwoss mwoss commented Feb 13, 2026

This PR fixes #405, where json:",omitzero" can behave incorrectly when Decimal is inside nested structs.

I followed the approach discussed in the issue and added a getValue func. It returns the already-initialized zeroInt when d.value == nil, so zero-value Decimal is handled consistently instead of leaving each call site to guard for nil.

I couldn’t find a cleaner option that didn’t spread the same logic around the codebase.

There may be a small performance cost from doing if d.value == nil checks a bit more often, but I think that tradeoff is worth it for correctness and better developer experience.

@mwoss
Copy link
Member Author

mwoss commented Feb 13, 2026

@abemedia @8xmx8 could you take a look? What do you think?

@abemedia
Copy link

@abemedia @8xmx8 could you take a look? What do you think?

Exactly how I would have done it!

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.Marshal with omitzero broken on decimal.Zero

2 participants