-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/unmrashall #13
Conversation
types/types.go
Outdated
@@ -89,6 +90,22 @@ func (o *NullBool) UnmarshalBSONValue(t bsontype.Type, bytes []byte) error { | |||
|
|||
return nil | |||
} | |||
func (o *NullBool) JSONUnmarshal(data []byte) error { |
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.
name of the method UnmarshalJSON
-> implements json.Unmarshaler
types/types.go
Outdated
@@ -89,6 +90,22 @@ func (o *NullBool) UnmarshalBSONValue(t bsontype.Type, bytes []byte) error { | |||
|
|||
return nil | |||
} | |||
func (o *NullBool) JSONUnmarshal(data []byte) error { | |||
if len(data) <= 0 { |
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 be just == 0
, but also need to handle the case of "null"
in bytes
if len(data) == 0 || bytes.Compare(jsonNullBytes, data) == 0 {
// value is true JSON null
types/types.go
Outdated
return nil | ||
} | ||
|
||
var isTrue bool |
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.
for simple types such as JSON boolean
, there are only two possible values, we can make a happy path
switch(utils.UnsafeString(data) {
case "true":
case "false"
default:
// Fall back to JSON marshaler to the thing
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #13 +/- ##
==========================================
- Coverage 31.88% 31.54% -0.34%
==========================================
Files 24 24
Lines 1700 1718 +18
==========================================
Hits 542 542
- Misses 1117 1135 +18
Partials 41 41
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
No description provided.