goccy / go-json

Fast JSON encoder/decoder compatible with encoding/json for Go
MIT License
3.11k stars 148 forks source link

Fix ignoring `omitempty` tag when field of custom type with pointer receiver on MarshalJSON implementation (fixes #488) #489

Open GCrispino opened 11 months ago

GCrispino commented 11 months ago

Fixes #488.

To do this I set fieldCode.isNilCheck to true in the case statement where isPtr && c.isPtrMarshalJSONType(fieldType): in Compiler's method structFieldCode. To be honest I don't exactly know all the implications to this, but this didn't break any tests and made the new test I added for the issue pass, so maybe this is a valid fix.