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.
Since EmptyAsNull got introduced in v1.1 with its framework, adding this feature was quite straightforward.
The slight performance toll of using reflect should only happen when actually opting in
ZeroAsNull
and I think there will be no better way of doing it without knowing the types beforehand.Definition of
omitempty
:Difference of reflect.Value.IsValid and reflect.Value.IsZero to prevent confusion:
So we can safely say that
reflect.Value.IsZero
is matching exactly the case ofomitempty
, if the user decides to opt in to this behaviour usingZeroAsNull
.There is strange behavior in tests! Even though I added the yaml testcase as last document in yamlA and yamlB all existing results (resultOfNoOptions, resultOfWithEmpty and the new resultOfWithZero) strangely expect the diff inbetween. You might want to look into that.
Edits to my branch are allowed if you want to extend the PR.