diff options
| author | Didier Spezia <didier.06@gmail.com> | 2015-04-28 11:20:19 +0000 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-07-22 15:39:54 +0000 |
| commit | 1a99ba55df902a2657d1ccfc52a60024c22dba98 (patch) | |
| tree | fbfdf0b27f08479365f476e4a3d7c86cab754b53 /src/encoding/json/decode.go | |
| parent | 1421bc10a4f61f92f3a3790a599fd7a02e7909d7 (diff) | |
| download | go-1a99ba55df902a2657d1ccfc52a60024c22dba98.tar.xz | |
encoding/json: fix decoding of JSON null values
JSON decoding currently fails for null values bound to any type
which does implement the JSON Unmarshaler interface without checking
for null values (such as time.Time).
It also fails for types implementing the TextUnmarshaler interface.
The expected behavior of the JSON decoding engine in such case is
to process null by keeping the value unchanged without producing
any error.
Make sure null values are handled by the decoding engine itself,
and never passed to the UnmarshalText or UnmarshalJSON methods.
Fixes #9037
Change-Id: I261d85587ba543ef6f1815555b2af9311034d5bb
Reviewed-on: https://go-review.googlesource.com/9376
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/encoding/json/decode.go')
| -rw-r--r-- | src/encoding/json/decode.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 530e8521dc..4d17c279bd 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -358,7 +358,7 @@ func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler, if v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } - if v.Type().NumMethod() > 0 { + if v.Type().NumMethod() > 0 && !decodingNull { if u, ok := v.Interface().(Unmarshaler); ok { return u, nil, reflect.Value{} } |
