mirror of
https://github.com/json-iterator/go.git
synced 2025-05-25 22:09:04 +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:
parent
96fcb84835
commit
11c1cce0d8
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user