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

serialise empty values as null (JSON) or empty element (XML) instead of the zero value of the type #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Southclaws
Copy link

See #2 for proposal and justification behind this change.

Copy link
Owner

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this fix!

@@ -277,7 +280,7 @@ func Example_jsonMarshalPresent() {
// }
}

func Example_jsonUnmarshalEmpty() {
func TestExample_jsonUnmarshalEmpty(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep this as an example? Examples already assert on the output.

@@ -335,6 +338,64 @@ func Example_jsonUnmarshalEmpty() {
// Uint64: false
// Uint: false
// Uintptr: false

t.Run("unmarshal null values to empty", func(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -82,17 +82,28 @@ func (o Optional[T]) ElseZero() (value T) {
// representation of the zero value of the type wrapped if there is no value
// wrapped by this optional.
func (o Optional[T]) String() string {
return fmt.Sprintf("%v", o.ElseZero())
if v, ok := o.Get(); ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

None yet

3 participants