json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.34k stars 1.02k forks source link

UnmarshalFromString can't Unmarshal empty string. #554

Closed yankooo closed 1 year ago

yankooo commented 3 years ago

for example:

func Test_customize_field_by_extension(t *testing.T) {
    should := require.New(t)
    cfg := jsoniter.Config{}.Froze()
    cfg.RegisterExtension(&testExtension{})
    obj := TestObject1{}
    err := cfg.UnmarshalFromString(``, &obj)
    should.Nil(err)
}

expect: err is nil, but err: "Read: unexpected value type: 0, error found in #0 byte of ...||..., bigger context ...||..."。

can't understand this error is a valid case?

fraenky8 commented 3 years ago

An empty string is not valid json. The stdlib throws an error as well: unexpected end of JSON input.

can't understand this error is a valid case?

To answer your question, yes this error is valid.