ITADN

Add support for omitzero struct tag

#415Pull Requestmwoss 创建于 2026-02-13
M
mwosscommented
This PR fixes [#405](https://github.com/shopspring/decimal/issues/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.
合并状态:未合并 1 条评论