Open
Description
See the code in any_object.go
func (any *objectLazyAny) ToVal(obj interface{}) {
iter := any.cfg.BorrowIterator(any.buf)
defer any.cfg.ReturnIterator(iter)
iter.ReadVal(obj)
}
When iter.ReadVal(obj)
failed, the error did not propagate to the objectLazyAny.err
.
Reproducing:
func TestJsoniter(t *testing.T) {
api := jsoniter.Config{
DisallowUnknownFields: true,
}.Froze()
var v struct{ Foo string }
// using Any.ToVal cannot see any errors
obj := api.BorrowIterator([]byte(`{"bar": true}`)).ReadAny()
obj.ToVal(&v)
t.Log(obj.LastError()) // this is nil, expecting "found unknown field: bar"
// using ReadVal can see the expected errors
iter := api.BorrowIterator([]byte(`{"bar": true}`))
iter.ReadVal(&v)
t.Log(iter.Error) // this is "found unknown field: bar"
}
Metadata
Metadata
Assignees
Labels
No labels