-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: Unmarshal doesn't work with embedded structs #29777
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
Comments
This is presumably a bug in go/src/encoding/json/decode.go Lines 477 to 479 in c077c74
The obvious workaround is to redefine |
I don't think this is a bug.
To fix, write:
Note: I currently rely on the current behavior of |
You'd mention
So, yes! According to the document, since |
I've just looked at an example with
This is much better, and the same can happen with
And, if someone knows exactly what he/she is doing, can simply ignore it, using: err := json.Unmarshal(data, &obj)
if err != nil && !json.IsNotEntireJSON(err) {
panic(err)
} |
CC @rsc @dsnet @bradfitz @mvdan for As @as notes, this is working as documented. On top of that, the |
I don't think there is anything more to be done here. (You're welcome to propose a change to the behavior of the package, but that should be filed as a separate proposal.) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, also on the playground
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I compiled and ran this program:
https://play.golang.org/p/toQBPltN0Lk
What did you expect to see?
I expected to see the field "Criteria" populated.
What did you see instead?
The field "Criteria" was not populated. If I, for example, remove the Q field entirely and instead embed OQ I get correct results (both Criteria and S are populated from the same json):
https://play.golang.org/p/ZoqJlTStEWF
I was expecting the same behaviour with Q as with OQ.
The text was updated successfully, but these errors were encountered: