mirror of
https://github.com/golang/go.git
synced 2025-11-08 12:41:02 +00:00
encoding/json: respect json.Marshaler when encoding byte kind slices
Fixes #13783. Change-Id: I0122c1f0cf4075acabf5f58241bded1835699dc1 Reviewed-on: https://go-review.googlesource.com/19725 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
2cefd12a1b
commit
cdc0ebbebe
2 changed files with 58 additions and 1 deletions
|
|
@ -679,7 +679,9 @@ func (se *sliceEncoder) encode(e *encodeState, v reflect.Value, _ bool) {
|
|||
|
||||
func newSliceEncoder(t reflect.Type) encoderFunc {
|
||||
// Byte slices get special treatment; arrays don't.
|
||||
if t.Elem().Kind() == reflect.Uint8 {
|
||||
if t.Elem().Kind() == reflect.Uint8 &&
|
||||
!t.Elem().Implements(marshalerType) &&
|
||||
!t.Elem().Implements(textMarshalerType) {
|
||||
return encodeByteSlice
|
||||
}
|
||||
enc := &sliceEncoder{newArrayEncoder(t)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue