mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
9169372749
commit
466001d05d
5 changed files with 240 additions and 49 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue