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: unexported embedded fields are not properly ignored #21121

Closed
dsnet opened this issue Jul 21, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@dsnet
Copy link
Member

commented Jul 21, 2017

Regression from Go1.8

https://golang.org/cl/33773 fixes the JSON marshaller to avoid serializing
embedded fields on unexported fields of non-struct type.
In order to determine whether a field is exported or not, it relies on
StructField.PkgPath to be non-empty if exported, but this is not always true
(see #21122).

Example reproduction:

type myInt int
type S struct{ *myInt }

s := S{new(myInt)}
*s.myInt = 5

b, _ := json.Marshal(s)
fmt.Println(string(b))

This prints:

{"myInt":5}

But should really print:

{}

\cc @ianlancetaylor

@gopherbot

This comment has been minimized.

Copy link

commented Jul 22, 2017

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

@gopherbot gopherbot closed this in b817359 Jul 22, 2017

@golang golang locked and limited conversation to collaborators Sep 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.