You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
It's supposed to prioritize omitempty before the string type. Instead, it prioritizes string and attempts to parse the value regardless of whether an empty value
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
json library ignores omitempty when multiple parameters used
encoding/json: ignores omitempty when multiple parameters used
Feb 10, 2016
omitempty only applies to JSON encoding, not decoding. (That appears to also be the case with encoding/asn1 and encoding/xml)
Go's encoding of that zero-value struct with omitempty is {}. If the Id field still had string set but not omitempty, it encodes as {"id": "0"}. It properly decodes both of those cases.
I'm not sure it's the correct thing to interpret "" as "0" for string-encoded integer fields. I know Go allows for this kind of encoding for 64-bit integers for safety (because JS only has 53-bit integer precision, IIRC), but is it a reasonably well specified practice? It looks like it was introduced in https://golang.org/cl/4918051
It's supposed to prioritize omitempty before the string type. Instead, it prioritizes string and attempts to parse the value regardless of whether an empty value
https://play.golang.org/p/Mq2eW3IR0A
The text was updated successfully, but these errors were encountered: