1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00

encoding/json: allow non-string type keys for (un-)marshal

ffbd31e9f7
This commit is contained in:
molon 2022-09-15 22:07:27 +08:00
parent 10b9ac0971
commit ffc487c633

View File

@ -2,11 +2,12 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/modern-go/reflect2"
"io" "io"
"reflect" "reflect"
"sort" "sort"
"unsafe" "unsafe"
"github.com/modern-go/reflect2"
) )
func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder {
@ -106,6 +107,7 @@ func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
} }
} }
if typ.Kind() != reflect.String {
if typ == textMarshalerType { if typ == textMarshalerType {
return &directTextMarshalerEncoder{ return &directTextMarshalerEncoder{
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
@ -117,6 +119,7 @@ func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
} }
} }
}
switch typ.Kind() { switch typ.Kind() {
case reflect.String: case reflect.String: