From 8daa0deeee4a147d6a83e6b980c3e00d4a588234 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 7 Mar 2022 12:51:44 +0100 Subject: [PATCH] Tweak the ISOTime marshaller @timofurrer does this fix #1384 --- types.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/types.go b/types.go index b851b984c..332830934 100644 --- a/types.go +++ b/types.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "net/url" + "reflect" "strconv" "time" ) @@ -119,7 +120,7 @@ func (a *ApproverIDsValue) EncodeValues(key string, v *url.Values) error { } // MarshalJSON implements the json.Marshaler interface -func (a *ApproverIDsValue) MarshalJSON() ([]byte, error) { +func (a ApproverIDsValue) MarshalJSON() ([]byte, error) { return json.Marshal(a.value) } @@ -155,7 +156,7 @@ func (a *AssigneeIDValue) EncodeValues(key string, v *url.Values) error { } // MarshalJSON implements the json.Marshaler interface -func (a *AssigneeIDValue) MarshalJSON() ([]byte, error) { +func (a AssigneeIDValue) MarshalJSON() ([]byte, error) { return json.Marshal(a.value) } @@ -191,7 +192,7 @@ func (a *ReviewerIDValue) EncodeValues(key string, v *url.Values) error { } // MarshalJSON implements the json.Marshaler interface -func (a *ReviewerIDValue) MarshalJSON() ([]byte, error) { +func (a ReviewerIDValue) MarshalJSON() ([]byte, error) { return json.Marshal(a.value) } @@ -362,6 +363,10 @@ const iso8601 = "2006-01-02" // MarshalJSON implements the json.Marshaler interface func (t ISOTime) MarshalJSON() ([]byte, error) { + if reflect.ValueOf(t).IsZero() { + return []byte(`null`), nil + } + if y := time.Time(t).Year(); y < 0 || y >= 10000 { // ISO 8901 uses 4 digits for the years return nil, errors.New("json: ISOTime year outside of range [0,9999]")