encoding/json: Unmarshal not reporting on skipped fields #10140
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 notifications@github.com
|
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 notifications@github.com
|
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: