• Ivan Bertona's avatar
    encoding/json: disallow unknown fields in Decoder · 2596a0c0
    Ivan Bertona authored
    Add a DisallowUnknownFields flag to Decoder.
    
    DisallowUnknownFields causes the Decoder to return an error when
    the the decoding destination is a struct and the input contains
    object keys which do not match any non-ignored, public field the
    destination, including keys whose value is set to null.
    
    Note: this fix has already been worked on in 27231, which seems
    to be abandoned. This version is a slightly simpler implementation
    and is up to date with the master branch.
    
    Fixes #15314
    
    Change-Id: I987a5857c52018df334f4d1a2360649c44a7175d
    Reviewed-on: https://go-review.googlesource.com/74830Reviewed-by: 's avatarJoe Tsai <joetsai@google.com>
    Run-TryBot: Joe Tsai <joetsai@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    2596a0c0
decode.go 33.1 KB