You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Merge branch 'master' of https://github.com/json-iterator/go
This commit is contained in:
		| @@ -13,6 +13,9 @@ func decoderOfArray(cfg *frozenConfig, prefix string, typ reflect.Type) ValDecod | ||||
| } | ||||
|  | ||||
| func encoderOfArray(cfg *frozenConfig, prefix string, typ reflect.Type) ValEncoder { | ||||
| 	if typ.Len() == 0 { | ||||
| 		return emptyArrayEncoder{} | ||||
| 	} | ||||
| 	encoder := encoderOfType(cfg, prefix+"[array]->", typ.Elem()) | ||||
| 	if typ.Elem().Kind() == reflect.Map { | ||||
| 		encoder = &OptionalEncoder{encoder} | ||||
| @@ -20,6 +23,20 @@ func encoderOfArray(cfg *frozenConfig, prefix string, typ reflect.Type) ValEncod | ||||
| 	return &arrayEncoder{typ, typ.Elem(), encoder} | ||||
| } | ||||
|  | ||||
| type emptyArrayEncoder struct{} | ||||
|  | ||||
| func (encoder emptyArrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||||
| 	stream.WriteEmptyArray() | ||||
| } | ||||
|  | ||||
| func (encoder emptyArrayEncoder) EncodeInterface(val interface{}, stream *Stream) { | ||||
| 	stream.WriteEmptyArray() | ||||
| } | ||||
|  | ||||
| func (encoder emptyArrayEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| type arrayEncoder struct { | ||||
| 	arrayType   reflect.Type | ||||
| 	elemType    reflect.Type | ||||
|   | ||||
| @@ -15,6 +15,15 @@ func Test_encode_fixed_array(t *testing.T) { | ||||
| 	should.Equal("[0.1,1]", output) | ||||
| } | ||||
|  | ||||
| func Test_encode_fixed_array_empty(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	type FixedArray [0]float64 | ||||
| 	fixed := FixedArray{} | ||||
| 	output, err := MarshalToString(fixed) | ||||
| 	should.Nil(err) | ||||
| 	should.Equal("[]", output) | ||||
| } | ||||
|  | ||||
| func Test_encode_fixed_array_of_map(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	type FixedArray [2]map[string]string | ||||
|   | ||||
		Reference in New Issue
	
	Block a user