From 3ebdcbdb180b9b89e7f270c22640e5ae4ba22f5b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 30 Oct 2020 19:08:20 +0800 Subject: [PATCH] Marshal invalid DeletedAt as null, fix #3693 --- soft_delete.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/soft_delete.go b/soft_delete.go index f3272246..b68cee43 100644 --- a/soft_delete.go +++ b/soft_delete.go @@ -26,7 +26,10 @@ func (n DeletedAt) Value() (driver.Value, error) { } func (n DeletedAt) MarshalJSON() ([]byte, error) { - return json.Marshal(n.Time) + if n.Valid { + return json.Marshal(n.Time) + } + return json.Marshal(nil) } func (n *DeletedAt) UnmarshalJSON(b []byte) error {