mirror of
https://github.com/json-iterator/go.git
synced 2025-06-03 22:27:26 +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) {
|
func (codec *nonEmptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
||||||
|
if iter.WhatIsNext() == NilValue {
|
||||||
|
iter.skipFourBytes('n', 'u', 'l', 'l')
|
||||||
|
return
|
||||||
|
}
|
||||||
nonEmptyInterface := (*nonEmptyInterface)(ptr)
|
nonEmptyInterface := (*nonEmptyInterface)(ptr)
|
||||||
if nonEmptyInterface.itab == nil {
|
if nonEmptyInterface.itab == nil {
|
||||||
iter.ReportError("read non-empty interface", "do not know which concrete type to decode to")
|
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)
|
err := ConfigCompatibleWithStandardLibrary.NewDecoder(&bytes.Buffer{}).Decode(&s)
|
||||||
assert.Equal(t, io.EOF, err)
|
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