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:
Håvard Haugen 2016-02-03 23:41:55 +01:00 committed by Brad Fitzpatrick
parent 2cefd12a1b
commit cdc0ebbebe
2 changed files with 58 additions and 1 deletions

View file

@ -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)}