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.Dismiss alert
What version of Go are you using (go version)?
go1.6.1 linux/amd64
What operating system and processor architecture are you using (go env)?
Linux, amd64
What did you do?
json.Unmarshal refuses to deserialise JSON into a custom interface var, even though the var (interface) points to a concrete object.
What did you expect to see?
json.Unmarshal should be able to inspect the concrete object behind custom interface to deserialise JSON, instead of throwing message "cannot unmarshal object into Go value of type "
@HouzuoGuo you have a pointer to an interface value containing a Lemon, but what you actually want is an interface value containing a pointer to a Lemon.
@HouzuoGuo pointer to interface of value is not equivalent to interface of
pointer, and only interface of pointer is sufficient. Interfaces do not
extend addressability to their contents like other kinds of values do, so
even though, with the pointer, the interface value itself is now
addressable, the boxed value is still a semantic copy of what you actually
want to modify.
@cesparehttps://github.com/cespare thanks and I understood that my
case is unconventional, but still I wish json.Unmarshal could figure it out
without having to use reflex.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub #15535 (comment)
bradfitz
changed the title
encoding/json: json.Unmarshal refuses to deserialise into custom interface var, even though the var points to a concrete object.
encoding/json: Unmarshal refuses to deserialize into custom interface var, even though the var points to a concrete object.
May 4, 2016
Sorry, the json package is pretty frozen. Regardless of whether it might be a good idea to make this work, at this point we're not going to make changes.
go version
)?go1.6.1 linux/amd64
go env
)?Linux, amd64
json.Unmarshal refuses to deserialise JSON into a custom interface var, even though the var (interface) points to a concrete object.
json.Unmarshal should be able to inspect the concrete object behind custom interface to deserialise JSON, instead of throwing message "cannot unmarshal object into Go value of type "
Full example, including a workaround:
https://play.golang.org/p/arj2sWQQnC
The text was updated successfully, but these errors were encountered: