Skip to content

Commit

Permalink
Coerce empty string to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
ikheetjeff committed Aug 23, 2024
1 parent bcede87 commit a42eb42
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion flex_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func (t Timestamp) MarshalJSON() ([]byte, error) {
func (t *Timestamp) UnmarshalJSON(b []byte) error {
// Timestamps are sometimes quoted, sometimes not, lets just always remove quotes just in case...
t.quoted = strings.Contains(string(b), `"`)
ts, err := strconv.Atoi(strings.Replace(string(b), `"`, "", -1))
withoutQuotes := strings.Replace(string(b), `"`, "", -1)
if len(withoutQuotes) == 0 {
return nil
}

ts, err := strconv.Atoi(withoutQuotes)
if err != nil {
return err
}
Expand Down

0 comments on commit a42eb42

Please # to comment.