aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/encode.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2016-05-23 12:21:57 -0400
committerRuss Cox <rsc@golang.org>2016-05-24 13:35:36 +0000
commit12610236375e2e981e370508548f3d51920df7e2 (patch)
tree76620b082221af4101b5b148dc34af7c8f685747 /src/encoding/json/encode.go
parentab4414773e27624abf4361e48a0ca0979e804970 (diff)
downloadgo-12610236375e2e981e370508548f3d51920df7e2.tar.xz
encoding/json: additional tests and fixes for []typedByte encoding/decoding
CL 19725 changed the encoding of []typedByte to look for typedByte.MarshalJSON and typedByte.MarshalText. Previously it was handled like []byte, producing a base64 encoding of the underlying byte data. CL 19725 forgot to look for (*typedByte).MarshalJSON and (*typedByte).MarshalText, as the marshaling of other slices would. Add test and fix for those. This CL also adds tests that the decoder can handle both the old and new encodings. (This was true even in Go 1.6, which is the only reason we can consider this not an incompatible change.) For #13783. Change-Id: I7cab8b6c0154a7f2d09335b7fa23173bcf856c37 Reviewed-on: https://go-review.googlesource.com/23294 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/encoding/json/encode.go')
-rw-r--r--src/encoding/json/encode.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go
index f91a78724c..3917084dc3 100644
--- a/src/encoding/json/encode.go
+++ b/src/encoding/json/encode.go
@@ -698,10 +698,11 @@ func (se *sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
func newSliceEncoder(t reflect.Type) encoderFunc {
// Byte slices get special treatment; arrays don't.
- if t.Elem().Kind() == reflect.Uint8 &&
- !t.Elem().Implements(marshalerType) &&
- !t.Elem().Implements(textMarshalerType) {
- return encodeByteSlice
+ if t.Elem().Kind() == reflect.Uint8 {
+ p := reflect.PtrTo(t.Elem())
+ if !p.Implements(marshalerType) && !p.Implements(textMarshalerType) {
+ return encodeByteSlice
+ }
}
enc := &sliceEncoder{newArrayEncoder(t)}
return enc.encode