-
Notifications
You must be signed in to change notification settings - Fork 26
fix: JSON empty string #479
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,12 +51,20 @@ func (dst *JSON) Set(src interface{}) error { | |
|
|
||
| switch value := src.(type) { | ||
| case string: | ||
| *dst = JSON{Bytes: []byte(value), Status: Present} | ||
| if value == "" { | ||
| *dst = JSON{Bytes: []byte(`""`), Status: Present} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Just null i think - no reason to distinguish between empty-string and nonexistent.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to keep the same behavior that go has when we call
|
||
| } else { | ||
| *dst = JSON{Bytes: []byte(value), Status: Present} | ||
| } | ||
| case *string: | ||
| if value == nil { | ||
| *dst = JSON{Status: Null} | ||
| } else { | ||
| *dst = JSON{Bytes: []byte(*value), Status: Present} | ||
| if *value == "" { | ||
| *dst = JSON{Bytes: []byte(`""`), Status: Present} | ||
| } else { | ||
| *dst = JSON{Bytes: []byte(*value), Status: Present} | ||
| } | ||
| } | ||
| case []byte: | ||
| if value == nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test with
*stringandstringcases removed from theswitch? Just let it fall todefault?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do that, then all of those strings will just be turned into
{}rather than""... Depends on the behavior we want...