Skip to content

Commit ffc487c

Browse files
committed
encoding/json: allow non-string type keys for (un-)marshal
golang/go@ffbd31e
1 parent 10b9ac0 commit ffc487c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Diff for: reflect_map.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package jsoniter
22

33
import (
44
"fmt"
5-
"github.com/modern-go/reflect2"
65
"io"
76
"reflect"
87
"sort"
98
"unsafe"
9+
10+
"github.com/modern-go/reflect2"
1011
)
1112

1213
func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder {
@@ -106,15 +107,17 @@ func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
106107
}
107108
}
108109

109-
if typ == textMarshalerType {
110-
return &directTextMarshalerEncoder{
111-
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
110+
if typ.Kind() != reflect.String {
111+
if typ == textMarshalerType {
112+
return &directTextMarshalerEncoder{
113+
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
114+
}
112115
}
113-
}
114-
if typ.Implements(textMarshalerType) {
115-
return &textMarshalerEncoder{
116-
valType: typ,
117-
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
116+
if typ.Implements(textMarshalerType) {
117+
return &textMarshalerEncoder{
118+
valType: typ,
119+
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
120+
}
118121
}
119122
}
120123

0 commit comments

Comments
 (0)