-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: Unmarshal not reporting on skipped fields #10140
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
It's a feature of I could imagine writing a little tool to take some source JSON and a On 12 March 2015 at 12:42, James Michael DuPont [email protected]
|
It would be great to have an optional warning if possible, or some callback routine that could be installed. I found this patch greatly useful in developing. Otherwise I ended up re-implementing the decoding routine to find the problem. |
There's nothing wrong with copying and pasting code. The hypothetical tool On 12 March 2015 at 12:54, James Michael DuPont [email protected]
|
I found it quite difficult to copy and paste the code because I had to copy the entire module because of undercased private functions that I could not call. Would need to make them public. In any case this would be a simple feature to add and would not break any compatibility to have an optional warning or strict mode. |
I agree that this would be a useful option. This issue has been brought up before and is already tracked by #6901. |
Closed as a dupe |
@h4ck3rm1k3 I meant literally copy the encoding/json directory somewhere else. |
yes that is what I had to do. My patch was based on that effort. @adg . thanks for the feedback |
When un-marshalling the json decoder will skip fields if it does not match the name.
This can be problematic if you have a typo or have a new field in the json. Would like some feedback from the decode modules when this happens.
Originally described in #10134
See also on stack overflow
http://stackoverflow.com/questions/20509444/go-json-unmarshal-not-picking-up-a-single-attribute-value
http://stackoverflow.com/questions/20943963/json-unmarshal-doesnt-seem-to-pay-attention-to-struct-tags
Proposed solution is to add this line to report unmatched fields
d.saveError(fmt.Errorf("json: unmatched field %s for %v", key, v.Type()))
h4ck3rm1k3/google-go@3befeea#diff-4299c3082a8bb7e546723132c992fa4cR586
The text was updated successfully, but these errors were encountered: