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: for "incomplete" structs Unmarshal matches wrong tag while the exact tag is not matched #28191

Closed
loeffel-io opened this issue Oct 13, 2018 · 3 comments

Comments

@loeffel-io
Copy link

loeffel-io commented Oct 13, 2018

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

https://play.golang.org

What did you do?

https://play.golang.org/p/0wQ7oqBrNYC

What did you expect to see?

{golang}

What did you see instead?

{google}

@loeffel-io loeffel-io changed the title Unmarshal "incomplete" struct is bad Unmarshal "incomplete" struct take the wrong field Oct 13, 2018
@loeffel-io loeffel-io changed the title Unmarshal "incomplete" struct take the wrong field Unmarshal of "incomplete" struct take the wrong field Oct 13, 2018
@ysmolski ysmolski changed the title Unmarshal of "incomplete" struct take the wrong field encoding/json: for "incomplete" structs Unmarshal matches wrong tag while the exact tag is not matched Oct 13, 2018
@ysmolski
Copy link
Member

ysmolski commented Oct 13, 2018

Although this is a feature of decoder to match case-insensitively fields with tags, it also means that decoder "prefers" the last matched item from the json: https://play.golang.org/p/ErQhH1aHNrZ

The same happens for struct fields: https://play.golang.org/p/4vwJF-c2Za9. Notice how part.AA has different values for each json string. Last matched value from the json, that is.

@ysmolski
Copy link
Member

oops, looks like it was discussed before.
@mvdan please confirm that this is a dup of #14750 and #28190

@mvdan
Copy link
Member

mvdan commented Oct 14, 2018

Yes, it seems like a duplicate to me. Even if the test case weren't exactly the same, it sounds to me like the solution should tackle both at the same time.

@mvdan mvdan closed this as completed Oct 14, 2018
@golang golang locked and limited conversation to collaborators Oct 14, 2019
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

4 participants