1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

array is just like struct, one element case special for interface{

This commit is contained in:
Tao Wen
2017-06-29 18:58:40 +08:00
parent a6673c983a
commit e6c24947ee
2 changed files with 20 additions and 2 deletions

View File

@ -56,7 +56,16 @@ func (encoder *arrayEncoder) EncodeInterface(val interface{}, stream *Stream) {
stream.WriteArrayEnd()
return
}
WriteToStream(val, stream, encoder)
elemType := encoder.arrayType.Elem()
if encoder.arrayType.Len() == 1 && (elemType.Kind() == reflect.Ptr ||elemType.Kind() == reflect.Map) {
ptr := uintptr(e.word)
e.word = unsafe.Pointer(&ptr)
}
if reflect.TypeOf(val).Kind() == reflect.Ptr {
encoder.Encode(unsafe.Pointer(&e.word), stream)
} else {
encoder.Encode(e.word, stream)
}
}
func (encoder *arrayEncoder) IsEmpty(ptr unsafe.Pointer) bool {