encoding/json: documented behavior unmarshaling JSON null into json.Unmarshaler is unclear #24903
Labels
Comments
But it doesn't set the field to the zero value. Consider: |
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using (
go version
)?1.10.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?N/A
What did you do?
I read the documentation for
json.Unmarshal
andjson.Unmarshaler.UnmarshalJSON
, and the relevant code:go/src/encoding/json/decode.go
Lines 482 to 494 in 568d484
What did you expect to see?
A statement to the effect that
json.Unmarshal
will zero the value before callingjson.Unmarshaler.UnmarshalJSON
.What did you see instead?
According to the documentation,
json.Unmarshal
passesnull
tojson.Unmarshaler.UnmarshalJSON
. However, it doesn't explain that, prior to making the call, it sets the field to the zero value.This is hinted at in the documentation for
json.Unmarshaler
, wherein it requires treating null inputs as a no-op, but this leaves the reader wondering what state the field is left in if it wasn't already the zero value.The text was updated successfully, but these errors were encountered: