Marshalling zero valued Deleted at to nullhttps://github.com/go-gorm/gorm/issues/3693
This commit is contained in:
parent
a8141b6cc9
commit
36bc5ef897
@ -26,12 +26,19 @@ func (n DeletedAt) Value() (driver.Value, error) {
|
||||
}
|
||||
|
||||
func (n DeletedAt) MarshalJSON() ([]byte, error) {
|
||||
if !n.Valid {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
return json.Marshal(n.Time)
|
||||
}
|
||||
|
||||
func (n *DeletedAt) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
n.Valid = false
|
||||
return nil
|
||||
}
|
||||
err := json.Unmarshal(b, &n.Time)
|
||||
if err == nil && !n.Time.IsZero() {
|
||||
if err == nil {
|
||||
n.Valid = true
|
||||
}
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user