From d6f1ca10c75bfb070042fbc1d054e31b5019259e Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Fri, 29 Nov 2019 23:00:31 -0800 Subject: [PATCH] whatever --- core/unifi/types.go | 4 +--- core/unifi/types_test.go | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/unifi/types.go b/core/unifi/types.go index 571f333b..840b0930 100644 --- a/core/unifi/types.go +++ b/core/unifi/types.go @@ -93,18 +93,16 @@ func (f *FlexInt) UnmarshalJSON(b []byte) error { case float64: f.Val = i f.Txt = strconv.FormatFloat(i, 'f', -1, 64) - return nil case string: f.Txt = i f.Val, _ = strconv.ParseFloat(i, 64) - return nil case nil: f.Txt = "0" f.Val = 0 - return nil default: return fmt.Errorf("cannot unmarshal to FlexInt: %s", b) } + return nil } // FlexBool provides a container and unmarshalling for fields that may be diff --git a/core/unifi/types_test.go b/core/unifi/types_test.go index 2b62cfcc..cd691158 100644 --- a/core/unifi/types_test.go +++ b/core/unifi/types_test.go @@ -15,10 +15,11 @@ func TestFlexInt(t *testing.T) { Seven FlexInt `json:"seven"` Auto FlexInt `json:"auto"` Channel FlexInt `json:"channel"` + Nil FlexInt `json:"nil"` } var r testReply // test unmarshalling the custom type three times with different values. - a.Nil(json.Unmarshal([]byte(`{"five": "5", "seven": 7, "auto": "auto"}`), &r)) + a.Nil(json.Unmarshal([]byte(`{"five": "5", "seven": 7, "auto": "auto", "nil": null}`), &r)) // test number in string. a.EqualValues(5, r.Five.Val) @@ -33,4 +34,7 @@ func TestFlexInt(t *testing.T) { a.NotNil(json.Unmarshal([]byte(`{"channel": {}}`), &r), "a non-string and non-number must produce an error.") a.EqualValues(0, r.Channel.Val) + // test null. + a.EqualValues(0, r.Nil.Val) + a.EqualValues("0", r.Nil.Txt) }