Skip to content

encoding/json: Unmarshal into struct field or a map does not validate invalid json.Number #14702

Closed
@brenol

Description

@brenol
  1. What version of Go are you using (go version)?
    go1.6 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
    (Use play.golang.org to provide a runnable example, if possible.)
    http://play.golang.org/p/8QZq-0vRch
  4. What did you expect to see?
    Unmarshal did not accept a invalid JSON as a json.Number, instead, it should raise an error
  5. What did you see instead?
    Unmarshal accepted a invalid JSON as a json.Number and did not raise an error
    encoding/json: Encode results in invalid json if json.Number is not a valid number #10281 is the one that actually fixed this issue, however, shouldn't unmarshal should also raise an error? Right now only Marshalling is an raising a error.

@edit
I actually did some further testing and it only happens when Unmarshalling into a struct field, as can be seen in the updated snippet above.

@edit2
It also happens when using map[string]json.Number and I have updated the test case accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions