serialise empty values as null (JSON) or empty element (XML) instead of the zero value of the type#3
Open
Southclaws wants to merge 4 commits into
Open
serialise empty values as null (JSON) or empty element (XML) instead of the zero value of the type#3Southclaws wants to merge 4 commits into
null (JSON) or empty element (XML) instead of the zero value of the type#3Southclaws wants to merge 4 commits into
Conversation
…d of the zero value of the type
unmarshal null into empty
Owner
leighmcculloch
left a comment
There was a problem hiding this comment.
Thanks for contributing this fix!
| } | ||
|
|
||
| func Example_jsonUnmarshalEmpty() { | ||
| func TestExample_jsonUnmarshalEmpty(t *testing.T) { |
Owner
There was a problem hiding this comment.
Could we keep this as an example? Examples already assert on the output.
| // Uint: false | ||
| // Uintptr: false | ||
|
|
||
| t.Run("unmarshal null values to empty", func(t *testing.T) { |
Owner
There was a problem hiding this comment.
Could you put this in a new example? Not a test please. The examples show up in docs and so help people understand how the library works.
| // wrapped by this optional. | ||
| func (o Optional[T]) String() string { | ||
| return fmt.Sprintf("%v", o.ElseZero()) | ||
| if v, ok := o.Get(); ok { |
Owner
There was a problem hiding this comment.
The comment for the function needs updating as it says if no value is set that the zero value of the type is returned, which is no longer the case.
sruehl
added a commit
to sruehl/go-optional
that referenced
this pull request
Aug 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See #2 for proposal and justification behind this change.