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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

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