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

Projects
None yet
3 participants
@loeffel-io
Copy link

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

@ysmolsky ysmolsky 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

@ysmolsky

This comment has been minimized.

Copy link
Member

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.

@ysmolsky

This comment has been minimized.

Copy link
Member

commented Oct 13, 2018

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

@mvdan

This comment has been minimized.

Copy link
Member

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 Oct 14, 2018

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