Merge pull request #4 from hasryan/issue3_intunmarshal

Avoid intermediate float64 storage for int64s during JSON unmarshal
This commit is contained in:
Greg 2014-09-17 09:50:23 +09:00
commit 26b8e82557

5
int.go
View file

@ -46,9 +46,10 @@ func (i *Int) UnmarshalJSON(data []byte) error {
var err error var err error
var v interface{} var v interface{}
json.Unmarshal(data, &v) json.Unmarshal(data, &v)
switch x := v.(type) { switch v.(type) {
case float64: 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{}: case map[string]interface{}:
err = json.Unmarshal(data, &i.NullInt64) err = json.Unmarshal(data, &i.NullInt64)
case nil: case nil: