mirror of https://github.com/goccy/go-json.git
Fix map key type
This commit is contained in:
parent
c9f1d0043e
commit
a9b9597c2e
|
@ -29,7 +29,7 @@ func (d *interfaceDecoder) numDecoder(s *stream) decoder {
|
|||
|
||||
var (
|
||||
interfaceMapType = type2rtype(
|
||||
reflect.TypeOf((*map[interface{}]interface{})(nil)).Elem(),
|
||||
reflect.TypeOf((*map[string]interface{})(nil)).Elem(),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -38,12 +38,12 @@ func (d *interfaceDecoder) decodeStream(s *stream, p uintptr) error {
|
|||
for {
|
||||
switch s.char() {
|
||||
case '{':
|
||||
var v map[interface{}]interface{}
|
||||
var v map[string]interface{}
|
||||
ptr := unsafe.Pointer(&v)
|
||||
d.dummy = ptr
|
||||
if err := newMapDecoder(
|
||||
interfaceMapType,
|
||||
newInterfaceDecoder(d.typ),
|
||||
newStringDecoder(),
|
||||
newInterfaceDecoder(d.typ),
|
||||
).decodeStream(s, uintptr(ptr)); err != nil {
|
||||
return err
|
||||
|
@ -120,12 +120,12 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p uintptr) (int64, e
|
|||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
case '{':
|
||||
var v map[interface{}]interface{}
|
||||
var v map[string]interface{}
|
||||
ptr := unsafe.Pointer(&v)
|
||||
d.dummy = ptr
|
||||
dec := newMapDecoder(
|
||||
interfaceMapType,
|
||||
newInterfaceDecoder(d.typ),
|
||||
newStringDecoder(),
|
||||
newInterfaceDecoder(d.typ),
|
||||
)
|
||||
cursor, err := dec.decode(buf, cursor, uintptr(ptr))
|
||||
|
|
|
@ -204,7 +204,7 @@ func Test_Decoder(t *testing.T) {
|
|||
var v interface{}
|
||||
assertErr(t, json.Unmarshal([]byte(`{"a": 1, "b": "c"}`), &v))
|
||||
assertEq(t, "interface.kind", "map", reflect.TypeOf(v).Kind().String())
|
||||
m := v.(map[interface{}]interface{})
|
||||
m := v.(map[string]interface{})
|
||||
assertEq(t, "interface", `1`, fmt.Sprint(m["a"]))
|
||||
assertEq(t, "interface", `c`, fmt.Sprint(m["b"]))
|
||||
})
|
||||
|
|
|
@ -108,8 +108,8 @@ func TestStructTagObjectKey(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Unmarshal(%#q) failed: %v", b, err)
|
||||
}
|
||||
for i, v := range f.(map[interface{}]interface{}) {
|
||||
switch i.(string) {
|
||||
for i, v := range f.(map[string]interface{}) {
|
||||
switch i {
|
||||
case tt.key:
|
||||
if s, ok := v.(string); !ok || s != tt.value {
|
||||
t.Fatalf("Unexpected value: %#q, want %v", s, tt.value)
|
||||
|
|
Loading…
Reference in New Issue