mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: skip unexpected null values
As discussed in issue 2540, nulls are allowed for any type in JSON so they should not result in an error during Unmarshal. Fixes #2540. R=rsc CC=golang-dev https://golang.org/cl/6759043
This commit is contained in:
parent
17623c0f13
commit
c90739e41e
2 changed files with 48 additions and 3 deletions
|
|
@ -617,12 +617,10 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
|
|||
switch c := item[0]; c {
|
||||
case 'n': // null
|
||||
switch v.Kind() {
|
||||
default:
|
||||
d.saveError(&UnmarshalTypeError{"null", v.Type()})
|
||||
case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
|
||||
v.Set(reflect.Zero(v.Type()))
|
||||
// otherwise, ignore null for primitives/string
|
||||
}
|
||||
|
||||
case 't', 'f': // true, false
|
||||
value := c == 't'
|
||||
switch v.Kind() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue