Marshalling zero valued Deleted at to nullhttps://github.com/go-gorm/gorm/issues/3693 (#3695)

This commit is contained in:
Amit Basuri
2020-11-02 07:33:39 +05:30
committed by GitHub
parent 3ebdcbdb18
commit 57b033e2dd
+5 -1
View File
@@ -33,8 +33,12 @@ func (n DeletedAt) MarshalJSON() ([]byte, error) {
}
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