Minor tweaks to null.Time UnmarshalJSON
This commit is contained in:
parent
e5f4f566ed
commit
639d4dad0a
1 changed files with 2 additions and 5 deletions
7
time.go
7
time.go
|
@ -86,14 +86,11 @@ func (t *Time) UnmarshalJSON(data []byte) error {
|
||||||
ti, tiOK := x["Time"].(string)
|
ti, tiOK := x["Time"].(string)
|
||||||
valid, validOK := x["Valid"].(bool)
|
valid, validOK := x["Valid"].(bool)
|
||||||
if !tiOK || !validOK {
|
if !tiOK || !validOK {
|
||||||
err = fmt.Errorf("json: unmarshalling map[string]interface{} into Go value of type null.Time requires key \"Time\" to be of type string and key \"Valid\" to be of type bool; found %T and %T, respectively", x["Time"], x["Valid"])
|
return fmt.Errorf("json: unmarshalling JSON object into Go value of type null.Time requires key \"Time\" to be of type string and key \"Valid\" to be of type bool; found %T and %T, respectively", x["Time"], x["Valid"])
|
||||||
break
|
|
||||||
}
|
}
|
||||||
err = t.Time.UnmarshalJSON([]byte(`"` + ti + `"`))
|
err = t.Time.UnmarshalJSON([]byte(`"` + ti + `"`))
|
||||||
t.Valid = valid
|
t.Valid = valid
|
||||||
if err == nil && t.Valid == false {
|
return err
|
||||||
return nil // Return here to prevent `Valid` from being set to true based on nil error below.
|
|
||||||
}
|
|
||||||
case nil:
|
case nil:
|
||||||
t.Valid = false
|
t.Valid = false
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue