diff --git a/decode_interface.go b/decode_interface.go index bc8d39a..0d0bfc2 100644 --- a/decode_interface.go +++ b/decode_interface.go @@ -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)) diff --git a/decode_test.go b/decode_test.go index c86565e..7c57b6b 100644 --- a/decode_test.go +++ b/decode_test.go @@ -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"])) }) diff --git a/tagkey_test.go b/tagkey_test.go index 8caf14f..29f5502 100644 --- a/tagkey_test.go +++ b/tagkey_test.go @@ -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)