From c0d98407b9dbe453836481b4c844bb5cc00b4a8c Mon Sep 17 00:00:00 2001 From: Ryan LaHue Date: Tue, 16 Sep 2014 17:43:59 -0700 Subject: [PATCH] Avoid []byte=>float64=>int64 conversion, instead going directly from []byte=>int64, to avoid issues with intermediate float64 representation --- int.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/int.go b/int.go index 692801b..0c710c5 100644 --- a/int.go +++ b/int.go @@ -46,9 +46,10 @@ func (i *Int) UnmarshalJSON(data []byte) error { var err error var v interface{} json.Unmarshal(data, &v) - switch x := v.(type) { + switch v.(type) { case float64: - i.Int64 = int64(x) + // Unmarshal again, directly to int64, to avoid intermediate float64 + err = json.Unmarshal(data, &i.Int64) case map[string]interface{}: err = json.Unmarshal(data, &i.NullInt64) case nil: