encoding/json: embedded *struct implementing UnmarshalJSON is nil and panics on Unmarshal #36716
Comments
Thanks for the thoughtful issue report. This is a duplicate of #30148. Feel free to discuss there if you have more to contribute. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/DZoQ9ro3jv7
my parent struct inherits
UnmarshalJSON(data []byte) error
from the embedded structhttps://github.com/golang/go/blob/master/src/encoding/json/decode.go#L492
in the
indirect()
functionif u, ok := v.Interface().(Unmarshaler); ok {
is true, but since the embedded struct is not allocated it will cause a nil pointer exceptionWhat did you expect to see?
&{&{}}
What did you see instead?
&{<nil>}
Unmarshal should allocate the embedded struct so that we can call UnmarshalJSON()
this would only be relevant if there were only 1 embedded struct which implements UnmarshalJSON
The text was updated successfully, but these errors were encountered: