jsonapi
jsonapi copied to clipboard
Behaviour for omitted fields in Unmarshal differs from json.Unmarshal
Describe the bug
When unmarshalling a omitted github.com/google/uuid UUID a error is returned that is not there on json.Unmarshal
Expected behavior Unmarshal should not be called for omitted fields
Links https://go.dev/play/p/tih4SyA3Jca
Hey @joris-bright thanks for submitting this issue! Apologies for the delay in responding. We will schedule some time to investigate the source of the bug, but if you have time / a pressing need, feel free to open a PR and we'd be happy to review it!
Thanks for the response. It's not a high priority for me, just something I noticed. If I have some spare time I'll take a look, but probably not anytime soon.
Hey @joris-bright, we looked into the issue.
According to jsonapi spec, id member is mandatory and should be a string.
Therefore, a valid string value is always expected for id. If you allowing empty/absent id, I suggest to explicitly state that by using jsonapi:omitempty tag (see this paragraph)
Slightly modified example demonstrating proper behavior: https://go.dev/play/p/X3AWls6S6WA
For non-primary members, omitted UUID value defaults to uuid.Nil.