Fix unmarshal null to existing value #407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unmarshaling null value on an existing field does not set it to nil.
The generated unmarshal code today adds this block of code that skips the field if it is null:
easyjson/gen/decoder.go
Lines 517 to 521 in 853c497
This means the field is skipped and does not get set to nil.
However, there is already an
if in.IsNull()
check on the individual field that sets the field to nil as expected:easyjson/gen/decoder.go
Lines 234 to 240 in 529b1f6
So removing the first check fixes this issue.
The added test fails today because it does not overwrite the
Ptr
field to nil, which is the stdlib behavior as shown here: https://goplay.tools/snippet/8Y3_1RK1C3uAs far as I can tell, the removed code should not affect anything else as the check is handled correctly after anyways, but please let me know if I am missing anything and how we can achieve the same behavior as stdlib.