diff --git a/soft_delete.go b/soft_delete.go index b13fc63f..b15a8148 100644 --- a/soft_delete.go +++ b/soft_delete.go @@ -3,6 +3,7 @@ package gorm import ( "database/sql" "database/sql/driver" + "encoding/json" "reflect" "gorm.io/gorm/clause" @@ -24,6 +25,18 @@ func (n DeletedAt) Value() (driver.Value, error) { return n.Time, nil } +func (n DeletedAt) MarshalJSON() ([]byte, error) { + return json.Marshal(n.Time) +} + +func (n *DeletedAt) UnmarshalJSON(b []byte) error { + err := json.Unmarshal(b, &n.Time) + if err == nil { + n.Valid = true + } + return err +} + func (DeletedAt) QueryClauses(f *schema.Field) []clause.Interface { return []clause.Interface{SoftDeleteQueryClause{Field: f}} }