1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-01 21:24:21 +02:00

#71 fix map key type of string alias

This commit is contained in:
Tao Wen 2017-06-26 11:52:22 +08:00
parent 0c07128d3c
commit 7d681fe2c2

View File

@ -37,7 +37,7 @@ func (decoder *mapDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
keyType := decoder.keyType
switch {
case keyType.Kind() == reflect.String:
realVal.SetMapIndex(reflect.ValueOf(keyStr), elem.Elem())
realVal.SetMapIndex(reflect.ValueOf(keyStr).Convert(keyType), elem.Elem())
return true
case keyType.Implements(textUnmarshalerType):
textUnmarshaler := reflect.New(keyType.Elem()).Interface().(encoding.TextUnmarshaler)
@ -172,7 +172,7 @@ func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
if i != 0 {
stream.WriteMore()
}
stream.WriteString(key.s)
stream.WriteVal(key.s) // might need html escape, so can not WriteString directly
stream.writeByte(':')
val := realVal.MapIndex(key.v).Interface()
encoder.elemEncoder.EncodeInterface(val, stream)