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 steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
http://play.golang.org/p/PQ7zcqcdN-
Pass pointer to an interface{} value that contains specific struct, instead of
interface{} value that contains pointer to specific struct.
What is the expected output?
main.B{Key:"", Val:""}
main.B{Key:"one", Val:"1"}
What do you see instead?
main.B{Key:"", Val:""}
map[string]interface {}{"Key":"one", "Val":"1"}
Which compiler are you using (5g, 6g, 8g, gccgo)?
6g
Which operating system are you using?
linux
Which version are you using? (run 'go version')
go version devel +b4c37131e846 Mon Oct 21 19:01:24 2013 -0400 linux/amd64
also works on release version
Please provide any additional information below.
Obvious solution to the code above would be http://play.golang.org/p/ffp11TvZoe
But should it *only* work that way?
The text was updated successfully, but these errors were encountered:
The first version of the unmarshal function is useless. You're just passing in a struct
value. Even if it "worked", the unmarshal function would populate a copy of that value
and you could never retrieve the contents of the JSON blob.
The issue is that the concrete value of the interface{} value is just a value, and is
not addressable, and so the JSON package can't modify it.
Change the line
a := &A{B: B{}}
to
a := &A{B: &B{}}
and you'll see that it works.
Here is a reduced example that demonstrates the difference:
http://play.golang.org/p/AyC8gSZh-d
by Lytvynov.A.V:
The text was updated successfully, but these errors were encountered: