encoding/json: add "overflow" struct tag option

Fixes #6213.

R=golang-dev, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/13180043
This commit is contained in:
Andrew Gerrand 2013-08-29 14:39:55 +10:00
parent 9169372749
commit 466001d05d
5 changed files with 240 additions and 49 deletions

View file

@ -1275,3 +1275,23 @@ func TestSkipArrayObjects(t *testing.T) {
t.Errorf("got error %q, want nil", err)
}
}
func TestDecodeOverflow(t *testing.T) {
json := `{"A":1,"B":2,"C":3}`
type S struct {
A int
E map[string]interface{} `json:",overflow"`
C int
}
var (
want = S{1, map[string]interface{}{"B": float64(2)}, 3}
dest S
)
err := Unmarshal([]byte(json), &dest)
if err != nil {
t.Errorf("got error %q, want nil", err)
}
if !reflect.DeepEqual(dest, want) {
t.Errorf("Got %+v; want %+v", dest, want)
}
}