You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	fix #217 when input is null, non-decodable type should not be considered as error, to be compatible with stdlib
This commit is contained in:
		| @@ -382,6 +382,10 @@ type nonEmptyInterfaceCodec struct { | ||||
| } | ||||
|  | ||||
| func (codec *nonEmptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||||
| 	if iter.WhatIsNext() == NilValue { | ||||
| 		iter.skipFourBytes('n', 'u', 'l', 'l') | ||||
| 		return | ||||
| 	} | ||||
| 	nonEmptyInterface := (*nonEmptyInterface)(ptr) | ||||
| 	if nonEmptyInterface.itab == nil { | ||||
| 		iter.ReportError("read non-empty interface", "do not know which concrete type to decode to") | ||||
|   | ||||
| @@ -191,3 +191,10 @@ func TestEOF(t *testing.T) { | ||||
| 	err := ConfigCompatibleWithStandardLibrary.NewDecoder(&bytes.Buffer{}).Decode(&s) | ||||
| 	assert.Equal(t, io.EOF, err) | ||||
| } | ||||
|  | ||||
| func TestDecodeErrorType(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	var err error | ||||
| 	should.Nil(Unmarshal([]byte("null"), &err)) | ||||
| 	should.NotNil(Unmarshal([]byte("123"), &err)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user