Skip to content

error in objectLazyAny.ToVal is not reported #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JasonMing opened this issue Mar 28, 2025 · 0 comments
Open

error in objectLazyAny.ToVal is not reported #709

JasonMing opened this issue Mar 28, 2025 · 0 comments

Comments

@JasonMing
Copy link

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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant