jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Behaviour for omitted fields in Unmarshal differs from json.Unmarshal

Open joris-bright opened this issue 2 years ago • 2 comments

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

joris-bright avatar Nov 30 '23 14:11 joris-bright

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!

DQSevilla avatar Jan 18 '24 16:01 DQSevilla

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.

joris-bright avatar Jan 22 '24 14:01 joris-bright

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.

The-Cop avatar Jan 16 '25 15:01 The-Cop