Option: fix nullable types getting serialized to nil on JSON null
This commit is contained in:
parent
fc5d10ced8
commit
b9d7ba4476
|
@ -49,6 +49,7 @@ func (b *NullableBoolData) UnmarshalJSON(json []byte) (err error) {
|
|||
s := string(json)
|
||||
|
||||
if s == "null" {
|
||||
*b = *NullBool
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ func (i *NullableColorData) UnmarshalJSON(json []byte) error {
|
|||
s := string(json)
|
||||
|
||||
if s == "null" {
|
||||
*i = *NullColor
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ func (u *NullableUintData) UnmarshalJSON(json []byte) error {
|
|||
s := string(json)
|
||||
|
||||
if s == "null" {
|
||||
*u = *NullUint
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -99,6 +100,7 @@ func (i *NullableIntData) UnmarshalJSON(json []byte) error {
|
|||
s := string(json)
|
||||
|
||||
if s == "null" {
|
||||
*i = *NullInt
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ type NullableStringData struct {
|
|||
Init bool
|
||||
}
|
||||
|
||||
// NullBool serializes to JSON null.
|
||||
// NullString serializes to JSON null.
|
||||
var NullString = &NullableStringData{}
|
||||
|
||||
// NewNullableString creates a new non-null NullableString with the value of the passed string.
|
||||
|
@ -42,6 +42,7 @@ func (s NullableStringData) MarshalJSON() ([]byte, error) {
|
|||
|
||||
func (s *NullableStringData) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*s = *NullString
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue