-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: ignore tag "-" not working on embedded sub structure when decoding #30701
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
Could you provide a full self-contained example, please? Also, note that the current Go version is 1.12; 1.10 is about a full year behind on the latest changes to |
This snippet should hit the same problem,
After unmarshalling, ID's are overwritten and set to the default value for I can reproduce that with current master (05051b5) too. |
Thanks a lot for the effort @giuscri i was about to create it. Here it is as a playground: https://play.golang.org/p/gBJ9aa_Tbbf So it appears you discovered the "-" tag is broken event for simple sub types (my test was refering to a complex map as subfield), but indeed a string will be reset to default value too. |
Note that the problem is not reproducible on simpler unmarshalling such as
|
Yes, first level fields tagged with "-" are ignored properly, the issue arise only in sub structures (potentially only in sub maps?). |
@mvdan Are the infos provided enough? If yes can we hope this to be fixed? This issue is quite big for anyone trying to build real life POST apis with complex structures... Regards, |
@mvdan ping, I think all infos provided should be enough, could we remove the "WaitingForInfo" and treat the bug? Regards, |
The information should be enough. I don't have the bandwidth to look at this bug right now, though. |
I see, thanks @mvdan ! Do you have any idea of when you'd have time to handle it? If not possible in the foreseeable future, I'll have to reconsider the architecture of my project and go for another solution. Thanks a lot, |
Go releases happen every six months, so even if a fix was out today, you wouldn't be able to use it for another four months. If you need an urgent fix, I'd suggest forking the package and hacking it to do what you want. |
The code you have provided works correctly. Notice the last sentence, which says it replaces not merges values. |
Hm i see, but then it's a design choice that is IMOH very weird. Real-life data is almost always complex and with multiple depth levels, which either needs to send partial data for perf reason, or just can't represent data full structure over JSON (ex: function handlers, map with non primitive types as key, etc). This prevent using go in any real life complexe situation, should this be considered an appropriate feature request? Or do you think it's too much of a change and might break existing application logic that rely on these sub-values be reinitialised? |
Closing as working as intended. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to unmarshall a complex object.
Lets say I decode the following json:
Into a structure instance hierarchy in which the AlreadyOrderedQuantityForReplenishment is not empty, after decoding this field will be set to and empty map, overriding the initial value.
What did you expect to see?
After the decode operation, I expect the AlreadyOrderedQuantityForReplenishment map to not be empty.
What did you see instead?
Before

After

Why is the decoder not ignoring the field all together as specified in the docs? Am I missing something?
Thanks a lot for any help,
The text was updated successfully, but these errors were encountered: