Skip to content
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

Fix unmarshal null values for non-pointer fields #411

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

neal
Copy link
Contributor

@neal neal commented Jan 9, 2025

#407 fixed the issue where an explicit null field did not reset the value, but a regression was introduced where previously it skipped any null values for non-pointer fields, that now returns an error.

This PR adds a IsNull() check before each unmarshal and the result is the same behavior as I see with stdlib now.

eg. stdlib ignores any null values for non-pointer fields: https://goplay.tools/snippet/dEJi7819RKc

The updated unit test also validates this behavior.

Without this change, the updated test fails to unmarshal:

--- FAIL: TestUnmarshalNull (0.00s)
    basic_test.go:341: easyjson.Unmarshal() error: parse error: expected string near offset 14 of 'String'
    basic_test.go:345: Wanted "bla", got ""
    basic_test.go:349: Wanted nil, got "bla"

@rvasily rvasily merged commit fe2707c into mailru:master Jan 11, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants