mirror of
https://github.com/golang/go.git
synced 2025-11-09 21:21:03 +00:00
encoding/json: encode nil encoding.TextMarshaler instance as "null"
Fixes #34235.
Change-Id: Ia3795fd18860530fa6a4b171545f525e784ffdcb
GitHub-Last-Rev: 1a319c4528
GitHub-Pull-Request: golang/go#34238
Reviewed-on: https://go-review.googlesource.com/c/go/+/194642
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
85c60bd0f3
commit
cc39d8087b
2 changed files with 29 additions and 8 deletions
|
|
@ -481,7 +481,11 @@ func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
|
|||
e.WriteString("null")
|
||||
return
|
||||
}
|
||||
m := v.Interface().(encoding.TextMarshaler)
|
||||
m, ok := v.Interface().(encoding.TextMarshaler)
|
||||
if !ok {
|
||||
e.WriteString("null")
|
||||
return
|
||||
}
|
||||
b, err := m.MarshalText()
|
||||
if err != nil {
|
||||
e.error(&MarshalerError{v.Type(), err})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue