Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: difference in behavior if embed a concrete type or interface for the same value #8386

Closed
gopherbot opened this issue Jul 17, 2014 · 4 comments

Comments

@gopherbot
Copy link

by bsr203:

What does 'go version' print?
go version go1.2.1 darwin/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

Please see this thread https://groups.google.com/forum/#!topic/golang-nuts/oi61EuR-a3g

In this example,  http://play.golang.org/p/YdFR9Aoj5O , the struct type is embedded, and
the json marshaled output is {"id":"_id_"}

In this example, http://play.golang.org/p/wchW_HBGKD ,  the interface is embedded, and
the json marshaled output is {"Ider":{"id":"_id_"}}


What should have happened instead?
I like to get the first output ({"id":"_id_"}) with the interface
embedded. 

Please provide any additional information below.
As per rog,

Unfortunately, unless the fields are statically determinable, 
I don't think you can. 

This is arguably a bug, as the documentation says: 
"Anonymous struct fields are usually marshaled as if their inner exported 
fields were fields in the outer struct" with no caveat to say 
that only applies if the inner field is not an interface type.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.4.

@rsc
Copy link
Contributor

rsc commented Oct 6, 2014

Comment 3:

Labels changed: added documentation.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 4:

CL https://golang.org/cl/149570043 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Oct 6, 2014

Comment 5:

This issue was closed by revision 8fd56bf.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
…ed ones

Fixes golang#8386.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/149570043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
…ed ones

Fixes golang#8386.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/149570043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
…ed ones

Fixes golang#8386.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/149570043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
…ed ones

Fixes golang#8386.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/149570043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants