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
Closed

encoding/json: unexported embedded fields are not properly ignored #21121

dsnet opened this issue Jul 21, 2017 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@dsnet
Copy link
Member

dsnet 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

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 21, 2017
@dsnet dsnet self-assigned this Jul 21, 2017
@dsnet dsnet added this to the Go1.9 milestone Jul 21, 2017
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 6, 2018
@rsc rsc unassigned dsnet Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants