mirror of
https://github.com/golang/go.git
synced 2025-11-08 20:51:02 +00:00
encoding/json: encode nil Marshaler as "null"
Fixes #16042. Change-Id: I0a28aa004246b7b0ffaaab457e077ad9035363c2 Reviewed-on: https://go-review.googlesource.com/31932 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c439a5d8b7
commit
add721ef91
2 changed files with 43 additions and 1 deletions
|
|
@ -443,7 +443,11 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
|
|||
e.WriteString("null")
|
||||
return
|
||||
}
|
||||
m := v.Interface().(Marshaler)
|
||||
m, ok := v.Interface().(Marshaler)
|
||||
if !ok {
|
||||
e.WriteString("null")
|
||||
return
|
||||
}
|
||||
b, err := m.MarshalJSON()
|
||||
if err == nil {
|
||||
// copy JSON into buffer, checking validity.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue