diff --git a/.example/container/garray/json_unmarshal.go b/.example/container/garray/json_unmarshal.go index 07e81adb0..99fb7adec 100644 --- a/.example/container/garray/json_unmarshal.go +++ b/.example/container/garray/json_unmarshal.go @@ -14,6 +14,6 @@ func main() { Scores *garray.IntArray } s := Student{} - json.Unmarshal(b, &s) + json.UnmarshalUseNumber(b, &s) fmt.Println(s) } diff --git a/.example/container/glist/json_unmarshal.go b/.example/container/glist/json_unmarshal.go index 313dfe570..32e654bcb 100644 --- a/.example/container/glist/json_unmarshal.go +++ b/.example/container/glist/json_unmarshal.go @@ -14,6 +14,6 @@ func main() { Scores *glist.List } s := Student{} - json.Unmarshal(b, &s) + json.UnmarshalUseNumber(b, &s) fmt.Println(s) } diff --git a/.example/container/gmap/gmap_json_unmarshal.go b/.example/container/gmap/gmap_json_unmarshal.go index af3c134a8..01bdc4f36 100644 --- a/.example/container/gmap/gmap_json_unmarshal.go +++ b/.example/container/gmap/gmap_json_unmarshal.go @@ -9,6 +9,6 @@ import ( func main() { m := gmap.Map{} s := []byte(`{"name":"john","score":100}`) - json.Unmarshal(s, &m) + json.UnmarshalUseNumber(s, &m) fmt.Println(m.Map()) } diff --git a/.example/container/gset/json_unmarshal.go b/.example/container/gset/json_unmarshal.go index 4e90ce823..f85afac05 100644 --- a/.example/container/gset/json_unmarshal.go +++ b/.example/container/gset/json_unmarshal.go @@ -14,6 +14,6 @@ func main() { Scores *gset.IntSet } s := Student{} - json.Unmarshal(b, &s) + json.UnmarshalUseNumber(b, &s) fmt.Println(s) } diff --git a/.example/container/gtype/json_unmarshal.go b/.example/container/gtype/json_unmarshal.go index 6b72cab08..7a17a1971 100644 --- a/.example/container/gtype/json_unmarshal.go +++ b/.example/container/gtype/json_unmarshal.go @@ -14,6 +14,6 @@ func main() { Scores *gtype.Interface } s := Student{} - json.Unmarshal(b, &s) + json.UnmarshalUseNumber(b, &s) fmt.Println(s) } diff --git a/.example/container/gvar/json_unmarshal.go b/.example/container/gvar/json_unmarshal.go index 31aa9843a..a4a9deba3 100644 --- a/.example/container/gvar/json_unmarshal.go +++ b/.example/container/gvar/json_unmarshal.go @@ -14,6 +14,6 @@ func main() { Scores *g.Var } s := Student{} - json.Unmarshal(b, &s) + json.UnmarshalUseNumber(b, &s) fmt.Println(s) } diff --git a/.example/encoding/gjson/issue#IZXU2.go b/.example/encoding/gjson/issue#IZXU2.go index e96f428d3..f56152fa6 100644 --- a/.example/encoding/gjson/issue#IZXU2.go +++ b/.example/encoding/gjson/issue#IZXU2.go @@ -140,7 +140,7 @@ var data = `{ func main() { struct1 := new(XinYanModel) - err := json.Unmarshal([]byte(data), struct1) + err := json.UnmarshalUseNumber([]byte(data), struct1) fmt.Println(err) fmt.Println(struct1) diff --git a/.example/net/ghttp/server/session/redis/redis_bigint.go b/.example/net/ghttp/server/session/redis/redis_bigint.go new file mode 100644 index 000000000..b8a5b3460 --- /dev/null +++ b/.example/net/ghttp/server/session/redis/redis_bigint.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/os/gsession" +) + +func main() { + type User struct { + Id int64 + Name string + } + s := g.Server() + s.SetSessionStorage(gsession.NewStorageRedis(g.Redis())) + s.Group("/", func(group *ghttp.RouterGroup) { + group.GET("/set", func(r *ghttp.Request) { + user := &User{ + Id: 1265476890672672808, + Name: "john", + } + if err := r.Session.Set("user", user); err != nil { + panic(err) + } + r.Response.Write("ok") + }) + group.GET("/get", func(r *ghttp.Request) { + r.Response.WriteJson(r.Session.Get("user")) + }) + group.GET("/clear", func(r *ghttp.Request) { + r.Session.Clear() + }) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/gtcp/pkg_operations/common/funcs/funcs.go b/.example/net/gtcp/pkg_operations/common/funcs/funcs.go index 368874c1e..4d8c33d10 100644 --- a/.example/net/gtcp/pkg_operations/common/funcs/funcs.go +++ b/.example/net/gtcp/pkg_operations/common/funcs/funcs.go @@ -30,7 +30,7 @@ func RecvPkg(conn *gtcp.Conn) (msg *types.Msg, err error) { return nil, err } else { msg = &types.Msg{} - err = json.Unmarshal(data, msg) + err = json.UnmarshalUseNumber(data, msg) if err != nil { return nil, fmt.Errorf("invalid package structure: %s", err.Error()) } diff --git a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go index b9758f893..b0820320c 100644 --- a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go +++ b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go @@ -21,7 +21,7 @@ func main() { break } info := &types.NodeInfo{} - if err := json.Unmarshal(data, info); err != nil { + if err := json.UnmarshalUseNumber(data, info); err != nil { glog.Errorf("invalid package structure: %s", err.Error()) } else { glog.Println(info) diff --git a/container/garray/garray_normal_any.go b/container/garray/garray_normal_any.go index 3e0324a10..616a59062 100644 --- a/container/garray/garray_normal_any.go +++ b/container/garray/garray_normal_any.go @@ -736,7 +736,7 @@ func (a *Array) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } return nil @@ -748,7 +748,7 @@ func (a *Array) UnmarshalValue(value interface{}) error { defer a.mu.Unlock() switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &a.array) + return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceAny(value) } diff --git a/container/garray/garray_normal_int.go b/container/garray/garray_normal_int.go index 10b64529d..10dbe16fe 100644 --- a/container/garray/garray_normal_int.go +++ b/container/garray/garray_normal_int.go @@ -735,7 +735,7 @@ func (a *IntArray) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } return nil @@ -747,7 +747,7 @@ func (a *IntArray) UnmarshalValue(value interface{}) error { defer a.mu.Unlock() switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &a.array) + return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceInt(value) } diff --git a/container/garray/garray_normal_str.go b/container/garray/garray_normal_str.go index 477156a8a..523a75123 100644 --- a/container/garray/garray_normal_str.go +++ b/container/garray/garray_normal_str.go @@ -750,7 +750,7 @@ func (a *StrArray) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } return nil @@ -762,7 +762,7 @@ func (a *StrArray) UnmarshalValue(value interface{}) error { defer a.mu.Unlock() switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &a.array) + return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceStr(value) } diff --git a/container/garray/garray_sorted_any.go b/container/garray/garray_sorted_any.go index 497ea9e67..91d7fa073 100644 --- a/container/garray/garray_sorted_any.go +++ b/container/garray/garray_sorted_any.go @@ -685,7 +685,7 @@ func (a *SortedArray) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } if a.comparator != nil && a.array != nil { @@ -706,7 +706,7 @@ func (a *SortedArray) UnmarshalValue(value interface{}) (err error) { defer a.mu.Unlock() switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &a.array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceAny(value) } diff --git a/container/garray/garray_sorted_int.go b/container/garray/garray_sorted_int.go index ab926a63a..6b96b2c3a 100644 --- a/container/garray/garray_sorted_int.go +++ b/container/garray/garray_sorted_int.go @@ -658,7 +658,7 @@ func (a *SortedIntArray) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } if a.array != nil { @@ -676,7 +676,7 @@ func (a *SortedIntArray) UnmarshalValue(value interface{}) (err error) { defer a.mu.Unlock() switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &a.array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceInt(value) } diff --git a/container/garray/garray_sorted_str.go b/container/garray/garray_sorted_str.go index 5450f5252..7b8e23b1b 100644 --- a/container/garray/garray_sorted_str.go +++ b/container/garray/garray_sorted_str.go @@ -671,7 +671,7 @@ func (a *SortedStrArray) UnmarshalJSON(b []byte) error { } a.mu.Lock() defer a.mu.Unlock() - if err := json.Unmarshal(b, &a.array); err != nil { + if err := json.UnmarshalUseNumber(b, &a.array); err != nil { return err } if a.array != nil { @@ -689,7 +689,7 @@ func (a *SortedStrArray) UnmarshalValue(value interface{}) (err error) { defer a.mu.Unlock() switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &a.array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array) default: a.array = gconv.SliceStr(value) } diff --git a/container/garray/garray_z_unit_normal_any_array_test.go b/container/garray/garray_z_unit_normal_any_array_test.go index b74fc7656..004e9bfd3 100644 --- a/container/garray/garray_z_unit_normal_any_array_test.go +++ b/container/garray/garray_z_unit_normal_any_array_test.go @@ -570,12 +570,12 @@ func TestArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.New() - err2 = json.Unmarshal(b2, &a2) + err2 = json.UnmarshalUseNumber(b2, &a2) t.Assert(err2, nil) t.Assert(a2.Slice(), s1) var a3 garray.Array - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -589,12 +589,12 @@ func TestArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.New() - err2 = json.Unmarshal(b2, &a2) + err2 = json.UnmarshalUseNumber(b2, &a2) t.Assert(err2, nil) t.Assert(a2.Slice(), s1) var a3 garray.Array - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -612,7 +612,7 @@ func TestArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) @@ -631,7 +631,7 @@ func TestArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) diff --git a/container/garray/garray_z_unit_normal_int_array_test.go b/container/garray/garray_z_unit_normal_int_array_test.go index 3d6b0b27b..ef1e763ef 100644 --- a/container/garray/garray_z_unit_normal_int_array_test.go +++ b/container/garray/garray_z_unit_normal_int_array_test.go @@ -615,11 +615,11 @@ func TestIntArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewIntArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s1) var a3 garray.IntArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -633,11 +633,11 @@ func TestIntArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewIntArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s1) var a3 garray.IntArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -655,7 +655,7 @@ func TestIntArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) @@ -674,7 +674,7 @@ func TestIntArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) diff --git a/container/garray/garray_z_unit_normal_str_array_test.go b/container/garray/garray_z_unit_normal_str_array_test.go index f4a02744c..be165863b 100644 --- a/container/garray/garray_z_unit_normal_str_array_test.go +++ b/container/garray/garray_z_unit_normal_str_array_test.go @@ -614,11 +614,11 @@ func TestStrArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewStrArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s1) var a3 garray.StrArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -632,11 +632,11 @@ func TestStrArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewStrArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s1) var a3 garray.StrArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -654,7 +654,7 @@ func TestStrArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) @@ -673,7 +673,7 @@ func TestStrArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, data["Scores"]) diff --git a/container/garray/garray_z_unit_sorted_any_array_test.go b/container/garray/garray_z_unit_sorted_any_array_test.go index f3ce498ea..baecec1b5 100644 --- a/container/garray/garray_z_unit_sorted_any_array_test.go +++ b/container/garray/garray_z_unit_sorted_any_array_test.go @@ -656,11 +656,11 @@ func TestSortedArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedArray(gutil.ComparatorString) - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) var a3 garray.SortedArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) t.Assert(a3.Interfaces(), s1) @@ -676,11 +676,11 @@ func TestSortedArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedArray(gutil.ComparatorString) - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) var a3 garray.SortedArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) t.Assert(a3.Interfaces(), s1) @@ -699,7 +699,7 @@ func TestSortedArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.AssertNE(user.Scores, nil) @@ -735,7 +735,7 @@ func TestSortedArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.AssertNE(user.Scores, nil) diff --git a/container/garray/garray_z_unit_sorted_int_array_test.go b/container/garray/garray_z_unit_sorted_int_array_test.go index c4e2e04b7..56b873f47 100644 --- a/container/garray/garray_z_unit_sorted_int_array_test.go +++ b/container/garray/garray_z_unit_sorted_int_array_test.go @@ -557,11 +557,11 @@ func TestSortedIntArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedIntArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) var a3 garray.SortedIntArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -576,11 +576,11 @@ func TestSortedIntArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedIntArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) var a3 garray.SortedIntArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) }) @@ -598,7 +598,7 @@ func TestSortedIntArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, []int{98, 99, 100}) @@ -617,7 +617,7 @@ func TestSortedIntArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, []int{98, 99, 100}) diff --git a/container/garray/garray_z_unit_sorted_str_array_test.go b/container/garray/garray_z_unit_sorted_str_array_test.go index 5be967e54..bab5c539e 100644 --- a/container/garray/garray_z_unit_sorted_str_array_test.go +++ b/container/garray/garray_z_unit_sorted_str_array_test.go @@ -577,12 +577,12 @@ func TestSortedStrArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedStrArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) t.Assert(a2.Interfaces(), s2) var a3 garray.SortedStrArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) t.Assert(a3.Interfaces(), s1) @@ -598,12 +598,12 @@ func TestSortedStrArray_Json(t *testing.T) { t.Assert(err1, err2) a2 := garray.NewSortedStrArray() - err1 = json.Unmarshal(b2, &a2) + err1 = json.UnmarshalUseNumber(b2, &a2) t.Assert(a2.Slice(), s2) t.Assert(a2.Interfaces(), s2) var a3 garray.SortedStrArray - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Slice(), s1) t.Assert(a3.Interfaces(), s1) @@ -622,7 +622,7 @@ func TestSortedStrArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, []string{"A", "A", "A+"}) @@ -641,7 +641,7 @@ func TestSortedStrArray_Json(t *testing.T) { t.Assert(err, nil) user := new(User) - err = json.Unmarshal(b, user) + err = json.UnmarshalUseNumber(b, user) t.Assert(err, nil) t.Assert(user.Name, data["Name"]) t.Assert(user.Scores, []string{"A", "A", "A+"}) diff --git a/container/glist/glist.go b/container/glist/glist.go index 1a3fd22bb..94319e50e 100644 --- a/container/glist/glist.go +++ b/container/glist/glist.go @@ -519,7 +519,7 @@ func (l *List) UnmarshalJSON(b []byte) error { l.list = list.New() } var array []interface{} - if err := json.Unmarshal(b, &array); err != nil { + if err := json.UnmarshalUseNumber(b, &array); err != nil { return err } l.PushBacks(array) @@ -536,7 +536,7 @@ func (l *List) UnmarshalValue(value interface{}) (err error) { var array []interface{} switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &array) default: array = gconv.SliceAny(value) } diff --git a/container/glist/glist_z_unit_test.go b/container/glist/glist_z_unit_test.go index d1dd57c3e..5e1da47c8 100644 --- a/container/glist/glist_z_unit_test.go +++ b/container/glist/glist_z_unit_test.go @@ -711,7 +711,7 @@ func TestList_Json(t *testing.T) { b, err := json.Marshal(a) t.Assert(err, nil) - err = json.Unmarshal(b, l) + err = json.UnmarshalUseNumber(b, l) t.Assert(err, nil) t.Assert(l.FrontAll(), a) }) @@ -721,7 +721,7 @@ func TestList_Json(t *testing.T) { b, err := json.Marshal(a) t.Assert(err, nil) - err = json.Unmarshal(b, &l) + err = json.UnmarshalUseNumber(b, &l) t.Assert(err, nil) t.Assert(l.FrontAll(), a) }) diff --git a/container/gmap/gmap_hash_any_any_map.go b/container/gmap/gmap_hash_any_any_map.go index acc10da60..a42cf26ea 100644 --- a/container/gmap/gmap_hash_any_any_map.go +++ b/container/gmap/gmap_hash_any_any_map.go @@ -476,7 +476,7 @@ func (m *AnyAnyMap) UnmarshalJSON(b []byte) error { m.data = make(map[interface{}]interface{}) } var data map[string]interface{} - if err := json.Unmarshal(b, &data); err != nil { + if err := json.UnmarshalUseNumber(b, &data); err != nil { return err } for k, v := range data { diff --git a/container/gmap/gmap_hash_int_any_map.go b/container/gmap/gmap_hash_int_any_map.go index d04c49a09..f99fd77d4 100644 --- a/container/gmap/gmap_hash_int_any_map.go +++ b/container/gmap/gmap_hash_int_any_map.go @@ -475,7 +475,7 @@ func (m *IntAnyMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[int]interface{}) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil @@ -490,7 +490,7 @@ func (m *IntAnyMap) UnmarshalValue(value interface{}) (err error) { } switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &m.data) + return json.UnmarshalUseNumber(gconv.Bytes(value), &m.data) default: for k, v := range gconv.Map(value) { m.data[gconv.Int(k)] = v diff --git a/container/gmap/gmap_hash_int_int_map.go b/container/gmap/gmap_hash_int_int_map.go index 4372246e3..3f8b8d411 100644 --- a/container/gmap/gmap_hash_int_int_map.go +++ b/container/gmap/gmap_hash_int_int_map.go @@ -446,7 +446,7 @@ func (m *IntIntMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[int]int) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil @@ -461,7 +461,7 @@ func (m *IntIntMap) UnmarshalValue(value interface{}) (err error) { } switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &m.data) + return json.UnmarshalUseNumber(gconv.Bytes(value), &m.data) default: for k, v := range gconv.Map(value) { m.data[gconv.Int(k)] = gconv.Int(v) diff --git a/container/gmap/gmap_hash_int_str_map.go b/container/gmap/gmap_hash_int_str_map.go index e92f8023a..c5f5ac323 100644 --- a/container/gmap/gmap_hash_int_str_map.go +++ b/container/gmap/gmap_hash_int_str_map.go @@ -446,7 +446,7 @@ func (m *IntStrMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[int]string) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil @@ -461,7 +461,7 @@ func (m *IntStrMap) UnmarshalValue(value interface{}) (err error) { } switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &m.data) + return json.UnmarshalUseNumber(gconv.Bytes(value), &m.data) default: for k, v := range gconv.Map(value) { m.data[gconv.Int(k)] = gconv.String(v) diff --git a/container/gmap/gmap_hash_str_any_map.go b/container/gmap/gmap_hash_str_any_map.go index 1ee97612e..04d70f664 100644 --- a/container/gmap/gmap_hash_str_any_map.go +++ b/container/gmap/gmap_hash_str_any_map.go @@ -471,7 +471,7 @@ func (m *StrAnyMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[string]interface{}) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil diff --git a/container/gmap/gmap_hash_str_int_map.go b/container/gmap/gmap_hash_str_int_map.go index 7a51f6ad9..7bc03cd34 100644 --- a/container/gmap/gmap_hash_str_int_map.go +++ b/container/gmap/gmap_hash_str_int_map.go @@ -449,7 +449,7 @@ func (m *StrIntMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[string]int) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil @@ -464,7 +464,7 @@ func (m *StrIntMap) UnmarshalValue(value interface{}) (err error) { } switch value.(type) { case string, []byte: - return json.Unmarshal(gconv.Bytes(value), &m.data) + return json.UnmarshalUseNumber(gconv.Bytes(value), &m.data) default: for k, v := range gconv.Map(value) { m.data[k] = gconv.Int(v) diff --git a/container/gmap/gmap_hash_str_str_map.go b/container/gmap/gmap_hash_str_str_map.go index 04f6c0698..ae68640c8 100644 --- a/container/gmap/gmap_hash_str_str_map.go +++ b/container/gmap/gmap_hash_str_str_map.go @@ -449,7 +449,7 @@ func (m *StrStrMap) UnmarshalJSON(b []byte) error { if m.data == nil { m.data = make(map[string]string) } - if err := json.Unmarshal(b, &m.data); err != nil { + if err := json.UnmarshalUseNumber(b, &m.data); err != nil { return err } return nil diff --git a/container/gmap/gmap_list_map.go b/container/gmap/gmap_list_map.go index 224cb9f63..790998da7 100644 --- a/container/gmap/gmap_list_map.go +++ b/container/gmap/gmap_list_map.go @@ -530,7 +530,7 @@ func (m *ListMap) UnmarshalJSON(b []byte) error { m.list = glist.New() } var data map[string]interface{} - if err := json.Unmarshal(b, &data); err != nil { + if err := json.UnmarshalUseNumber(b, &data); err != nil { return err } for key, value := range data { diff --git a/container/gmap/gmap_z_unit_any_any_test.go b/container/gmap/gmap_z_unit_any_any_test.go index 4a06b4e04..3a5c78592 100644 --- a/container/gmap/gmap_z_unit_any_any_test.go +++ b/container/gmap/gmap_z_unit_any_any_test.go @@ -255,7 +255,7 @@ func Test_AnyAnyMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.New() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -269,7 +269,7 @@ func Test_AnyAnyMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.Map - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gmap/gmap_z_unit_int_any_test.go b/container/gmap/gmap_z_unit_int_any_test.go index c6ac46486..2c6bc25ea 100644 --- a/container/gmap/gmap_z_unit_int_any_test.go +++ b/container/gmap/gmap_z_unit_int_any_test.go @@ -245,7 +245,7 @@ func Test_IntAnyMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewIntAnyMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get(1), data[1]) t.Assert(m.Get(2), data[2]) diff --git a/container/gmap/gmap_z_unit_int_int_test.go b/container/gmap/gmap_z_unit_int_int_test.go index 37b940152..762ba223f 100644 --- a/container/gmap/gmap_z_unit_int_int_test.go +++ b/container/gmap/gmap_z_unit_int_int_test.go @@ -251,7 +251,7 @@ func Test_IntIntMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewIntIntMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get(1), data[1]) t.Assert(m.Get(2), data[2]) diff --git a/container/gmap/gmap_z_unit_int_str_test.go b/container/gmap/gmap_z_unit_int_str_test.go index 2b4292ef1..6a91b00f6 100644 --- a/container/gmap/gmap_z_unit_int_str_test.go +++ b/container/gmap/gmap_z_unit_int_str_test.go @@ -249,7 +249,7 @@ func Test_IntStrMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewIntStrMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get(1), data[1]) t.Assert(m.Get(2), data[2]) diff --git a/container/gmap/gmap_z_unit_list_map_test.go b/container/gmap/gmap_z_unit_list_map_test.go index 045d673a7..4a226cfca 100644 --- a/container/gmap/gmap_z_unit_list_map_test.go +++ b/container/gmap/gmap_z_unit_list_map_test.go @@ -204,7 +204,7 @@ func Test_ListMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewListMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -219,7 +219,7 @@ func Test_ListMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.ListMap - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gmap/gmap_z_unit_str_any_test.go b/container/gmap/gmap_z_unit_str_any_test.go index 22180c901..1cee92de2 100644 --- a/container/gmap/gmap_z_unit_str_any_test.go +++ b/container/gmap/gmap_z_unit_str_any_test.go @@ -243,7 +243,7 @@ func Test_StrAnyMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewStrAnyMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -257,7 +257,7 @@ func Test_StrAnyMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.StrAnyMap - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gmap/gmap_z_unit_str_int_test.go b/container/gmap/gmap_z_unit_str_int_test.go index 56ba1141a..eb80c7760 100644 --- a/container/gmap/gmap_z_unit_str_int_test.go +++ b/container/gmap/gmap_z_unit_str_int_test.go @@ -247,7 +247,7 @@ func Test_StrIntMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewStrIntMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -261,7 +261,7 @@ func Test_StrIntMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.StrIntMap - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gmap/gmap_z_unit_str_str_test.go b/container/gmap/gmap_z_unit_str_str_test.go index 0dfffd3a5..e64a36af1 100644 --- a/container/gmap/gmap_z_unit_str_str_test.go +++ b/container/gmap/gmap_z_unit_str_str_test.go @@ -244,7 +244,7 @@ func Test_StrStrMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewStrStrMap() - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -258,7 +258,7 @@ func Test_StrStrMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.StrStrMap - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gmap/gmap_z_unit_tree_map_test.go b/container/gmap/gmap_z_unit_tree_map_test.go index e008d9986..470cf40f0 100644 --- a/container/gmap/gmap_z_unit_tree_map_test.go +++ b/container/gmap/gmap_z_unit_tree_map_test.go @@ -188,7 +188,7 @@ func Test_TreeMap_Json(t *testing.T) { t.Assert(err, nil) m := gmap.NewTreeMap(gutil.ComparatorString) - err = json.Unmarshal(b, m) + err = json.UnmarshalUseNumber(b, m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) @@ -202,7 +202,7 @@ func Test_TreeMap_Json(t *testing.T) { t.Assert(err, nil) var m gmap.TreeMap - err = json.Unmarshal(b, &m) + err = json.UnmarshalUseNumber(b, &m) t.Assert(err, nil) t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k2"), data["k2"]) diff --git a/container/gset/gset_any_set.go b/container/gset/gset_any_set.go index f6ceccfa6..9db79a47a 100644 --- a/container/gset/gset_any_set.go +++ b/container/gset/gset_any_set.go @@ -477,7 +477,7 @@ func (set *Set) UnmarshalJSON(b []byte) error { set.data = make(map[interface{}]struct{}) } var array []interface{} - if err := json.Unmarshal(b, &array); err != nil { + if err := json.UnmarshalUseNumber(b, &array); err != nil { return err } for _, v := range array { @@ -496,7 +496,7 @@ func (set *Set) UnmarshalValue(value interface{}) (err error) { var array []interface{} switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &array) default: array = gconv.SliceAny(value) } diff --git a/container/gset/gset_int_set.go b/container/gset/gset_int_set.go index 18d6ca9e2..39a98d9f3 100644 --- a/container/gset/gset_int_set.go +++ b/container/gset/gset_int_set.go @@ -437,7 +437,7 @@ func (set *IntSet) UnmarshalJSON(b []byte) error { set.data = make(map[int]struct{}) } var array []int - if err := json.Unmarshal(b, &array); err != nil { + if err := json.UnmarshalUseNumber(b, &array); err != nil { return err } for _, v := range array { @@ -456,7 +456,7 @@ func (set *IntSet) UnmarshalValue(value interface{}) (err error) { var array []int switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &array) default: array = gconv.SliceInt(value) } diff --git a/container/gset/gset_str_set.go b/container/gset/gset_str_set.go index d800af22e..68b4ec6bc 100644 --- a/container/gset/gset_str_set.go +++ b/container/gset/gset_str_set.go @@ -465,7 +465,7 @@ func (set *StrSet) UnmarshalJSON(b []byte) error { set.data = make(map[string]struct{}) } var array []string - if err := json.Unmarshal(b, &array); err != nil { + if err := json.UnmarshalUseNumber(b, &array); err != nil { return err } for _, v := range array { @@ -484,7 +484,7 @@ func (set *StrSet) UnmarshalValue(value interface{}) (err error) { var array []string switch value.(type) { case string, []byte: - err = json.Unmarshal(gconv.Bytes(value), &array) + err = json.UnmarshalUseNumber(gconv.Bytes(value), &array) default: array = gconv.SliceStr(value) } diff --git a/container/gset/gset_z_unit_any_test.go b/container/gset/gset_z_unit_any_test.go index d9d6e6479..bef113955 100644 --- a/container/gset/gset_z_unit_any_test.go +++ b/container/gset/gset_z_unit_any_test.go @@ -327,7 +327,7 @@ func TestSet_Json(t *testing.T) { t.Assert(err1, err2) a2 := gset.New() - err2 = json.Unmarshal(b2, &a2) + err2 = json.UnmarshalUseNumber(b2, &a2) t.Assert(err2, nil) t.Assert(a2.Contains("a"), true) t.Assert(a2.Contains("b"), true) @@ -336,7 +336,7 @@ func TestSet_Json(t *testing.T) { t.Assert(a2.Contains("e"), false) var a3 gset.Set - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Contains("a"), true) t.Assert(a3.Contains("b"), true) diff --git a/container/gset/gset_z_unit_int_test.go b/container/gset/gset_z_unit_int_test.go index e45fa21d4..618200691 100644 --- a/container/gset/gset_z_unit_int_test.go +++ b/container/gset/gset_z_unit_int_test.go @@ -358,7 +358,7 @@ func TestIntSet_Json(t *testing.T) { t.Assert(err1, err2) a2 := gset.NewIntSet() - err2 = json.Unmarshal(b2, &a2) + err2 = json.UnmarshalUseNumber(b2, &a2) t.Assert(err2, nil) t.Assert(a2.Contains(1), true) t.Assert(a2.Contains(2), true) @@ -367,7 +367,7 @@ func TestIntSet_Json(t *testing.T) { t.Assert(a2.Contains(5), false) var a3 gset.IntSet - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a2.Contains(1), true) t.Assert(a2.Contains(2), true) diff --git a/container/gset/gset_z_unit_str_test.go b/container/gset/gset_z_unit_str_test.go index 33586cd8e..ab57cf6ca 100644 --- a/container/gset/gset_z_unit_str_test.go +++ b/container/gset/gset_z_unit_str_test.go @@ -404,7 +404,7 @@ func TestStrSet_Json(t *testing.T) { t.Assert(err1, err2) a2 := gset.NewStrSet() - err2 = json.Unmarshal(b2, &a2) + err2 = json.UnmarshalUseNumber(b2, &a2) t.Assert(err2, nil) t.Assert(a2.Contains("a"), true) t.Assert(a2.Contains("b"), true) @@ -413,7 +413,7 @@ func TestStrSet_Json(t *testing.T) { t.Assert(a2.Contains("e"), false) var a3 gset.StrSet - err := json.Unmarshal(b2, &a3) + err := json.UnmarshalUseNumber(b2, &a3) t.Assert(err, nil) t.Assert(a3.Contains("a"), true) t.Assert(a3.Contains("b"), true) diff --git a/container/gtree/gtree_redblacktree.go b/container/gtree/gtree_redblacktree.go index 33a8d45dd..7ccf0fd1c 100644 --- a/container/gtree/gtree_redblacktree.go +++ b/container/gtree/gtree_redblacktree.go @@ -937,7 +937,7 @@ func (tree *RedBlackTree) UnmarshalJSON(b []byte) error { tree.comparator = gutil.ComparatorString } var data map[string]interface{} - if err := json.Unmarshal(b, &data); err != nil { + if err := json.UnmarshalUseNumber(b, &data); err != nil { return err } for k, v := range data { diff --git a/container/gtype/interface.go b/container/gtype/interface.go index acb26f46c..8cd554dde 100644 --- a/container/gtype/interface.go +++ b/container/gtype/interface.go @@ -58,7 +58,7 @@ func (v *Interface) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal. func (v *Interface) UnmarshalJSON(b []byte) error { var i interface{} - err := json.Unmarshal(b, &i) + err := json.UnmarshalUseNumber(b, &i) if err != nil { return err } diff --git a/container/gtype/z_unit_bool_test.go b/container/gtype/z_unit_bool_test.go index 297f5de85..b30738a84 100644 --- a/container/gtype/z_unit_bool_test.go +++ b/container/gtype/z_unit_bool_test.go @@ -55,16 +55,16 @@ func Test_Bool_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { var err error i := gtype.NewBool() - err = json.Unmarshal([]byte("true"), &i) + err = json.UnmarshalUseNumber([]byte("true"), &i) t.Assert(err, nil) t.Assert(i.Val(), true) - err = json.Unmarshal([]byte("false"), &i) + err = json.UnmarshalUseNumber([]byte("false"), &i) t.Assert(err, nil) t.Assert(i.Val(), false) - err = json.Unmarshal([]byte("1"), &i) + err = json.UnmarshalUseNumber([]byte("1"), &i) t.Assert(err, nil) t.Assert(i.Val(), true) - err = json.Unmarshal([]byte("0"), &i) + err = json.UnmarshalUseNumber([]byte("0"), &i) t.Assert(err, nil) t.Assert(i.Val(), false) }) @@ -78,7 +78,7 @@ func Test_Bool_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewBool() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i.Val()) }) @@ -91,7 +91,7 @@ func Test_Bool_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewBool() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i.Val()) }) diff --git a/container/gtype/z_unit_byte_test.go b/container/gtype/z_unit_byte_test.go index 0a6c77df4..86ba6cfb9 100644 --- a/container/gtype/z_unit_byte_test.go +++ b/container/gtype/z_unit_byte_test.go @@ -53,7 +53,7 @@ func Test_Byte_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { var err error i := gtype.NewByte() - err = json.Unmarshal([]byte("49"), &i) + err = json.UnmarshalUseNumber([]byte("49"), &i) t.Assert(err, nil) t.Assert(i.Val(), "49") }) diff --git a/container/gtype/z_unit_bytes_test.go b/container/gtype/z_unit_bytes_test.go index 234307ae8..49145d290 100644 --- a/container/gtype/z_unit_bytes_test.go +++ b/container/gtype/z_unit_bytes_test.go @@ -39,7 +39,7 @@ func Test_Bytes_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewBytes() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), b) }) diff --git a/container/gtype/z_unit_float32_test.go b/container/gtype/z_unit_float32_test.go index 14914ed27..7aff7f79c 100644 --- a/container/gtype/z_unit_float32_test.go +++ b/container/gtype/z_unit_float32_test.go @@ -40,7 +40,7 @@ func Test_Float32_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewFloat32() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), v) }) diff --git a/container/gtype/z_unit_float64_test.go b/container/gtype/z_unit_float64_test.go index 717e0500a..1ba6cfa1e 100644 --- a/container/gtype/z_unit_float64_test.go +++ b/container/gtype/z_unit_float64_test.go @@ -38,7 +38,7 @@ func Test_Float64_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewFloat64() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), v) }) diff --git a/container/gtype/z_unit_int32_test.go b/container/gtype/z_unit_int32_test.go index c2b7d5690..cf2250ae5 100644 --- a/container/gtype/z_unit_int32_test.go +++ b/container/gtype/z_unit_int32_test.go @@ -51,7 +51,7 @@ func Test_Int32_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewInt32() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), v) }) diff --git a/container/gtype/z_unit_int64_test.go b/container/gtype/z_unit_int64_test.go index 85a0bbea8..8b5c6a299 100644 --- a/container/gtype/z_unit_int64_test.go +++ b/container/gtype/z_unit_int64_test.go @@ -50,7 +50,7 @@ func Test_Int64_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewInt64() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i) }) diff --git a/container/gtype/z_unit_int_test.go b/container/gtype/z_unit_int_test.go index 49e44b2f2..939ef81e9 100644 --- a/container/gtype/z_unit_int_test.go +++ b/container/gtype/z_unit_int_test.go @@ -50,7 +50,7 @@ func Test_Int_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewInt() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), v) }) diff --git a/container/gtype/z_unit_interface_test.go b/container/gtype/z_unit_interface_test.go index 990951b53..130102f63 100644 --- a/container/gtype/z_unit_interface_test.go +++ b/container/gtype/z_unit_interface_test.go @@ -40,7 +40,7 @@ func Test_Interface_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.New() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), s) }) diff --git a/container/gtype/z_unit_string_test.go b/container/gtype/z_unit_string_test.go index 16132474d..3b42cca41 100644 --- a/container/gtype/z_unit_string_test.go +++ b/container/gtype/z_unit_string_test.go @@ -38,7 +38,7 @@ func Test_String_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewString() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), s) }) diff --git a/container/gtype/z_unit_uint32_test.go b/container/gtype/z_unit_uint32_test.go index 1e9d0a508..abe188dad 100644 --- a/container/gtype/z_unit_uint32_test.go +++ b/container/gtype/z_unit_uint32_test.go @@ -50,7 +50,7 @@ func Test_Uint32_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewUint32() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i) }) diff --git a/container/gtype/z_unit_uint64_test.go b/container/gtype/z_unit_uint64_test.go index 1c97b53c5..ab05217ff 100644 --- a/container/gtype/z_unit_uint64_test.go +++ b/container/gtype/z_unit_uint64_test.go @@ -55,7 +55,7 @@ func Test_Uint64_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewUint64() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i) }) diff --git a/container/gtype/z_unit_uint_test.go b/container/gtype/z_unit_uint_test.go index d9237940a..4f314856e 100644 --- a/container/gtype/z_unit_uint_test.go +++ b/container/gtype/z_unit_uint_test.go @@ -49,7 +49,7 @@ func Test_Uint_JSON(t *testing.T) { t.Assert(b1, b2) i2 := gtype.NewUint() - err := json.Unmarshal(b2, &i2) + err := json.UnmarshalUseNumber(b2, &i2) t.Assert(err, nil) t.Assert(i2.Val(), i) }) diff --git a/container/gvar/gvar.go b/container/gvar/gvar.go index 1babba781..36480d71a 100644 --- a/container/gvar/gvar.go +++ b/container/gvar/gvar.go @@ -189,7 +189,7 @@ func (v *Var) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal. func (v *Var) UnmarshalJSON(b []byte) error { var i interface{} - err := json.Unmarshal(b, &i) + err := json.UnmarshalUseNumber(b, &i) if err != nil { return err } diff --git a/container/gvar/gvar_z_unit_json_test.go b/container/gvar/gvar_z_unit_json_test.go index 53dc856f3..dde33a732 100644 --- a/container/gvar/gvar_z_unit_json_test.go +++ b/container/gvar/gvar_z_unit_json_test.go @@ -41,7 +41,7 @@ func TestVar_Json(t *testing.T) { b, err := json.Marshal(s) t.Assert(err, nil) - err = json.Unmarshal(b, v) + err = json.UnmarshalUseNumber(b, v) t.Assert(err, nil) t.Assert(v.String(), s) }) @@ -52,7 +52,7 @@ func TestVar_Json(t *testing.T) { b, err := json.Marshal(s) t.Assert(err, nil) - err = json.Unmarshal(b, &v) + err = json.UnmarshalUseNumber(b, &v) t.Assert(err, nil) t.Assert(v.String(), s) }) diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index 31fd0007d..bafd477bc 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -488,7 +488,7 @@ func (m *Model) doGetAllBySql(sql string, args ...interface{}) (result Result, e } else { // Other cache, it needs conversion. var result Result - if err = json.Unmarshal(v.Bytes(), &result); err != nil { + if err = json.UnmarshalUseNumber(v.Bytes(), &result); err != nil { return nil, err } else { return result, nil diff --git a/encoding/gjson/gjson.go b/encoding/gjson/gjson.go index df30d9e75..573acce39 100644 --- a/encoding/gjson/gjson.go +++ b/encoding/gjson/gjson.go @@ -22,7 +22,7 @@ const ( defaultSplitChar = '.' ) -// The customized JSON struct. +// Json is the customized JSON struct. type Json struct { mu *rwmutex.RWMutex p *interface{} // Pointer for hierarchical data access, it's the root of data in default. @@ -30,8 +30,8 @@ type Json struct { vc bool // Violence Check(false in default), which is used to access data when the hierarchical data key contains separator char. } -// Option for Json object creating. -type Option struct { +// Options for Json object creating. +type Options struct { Safe bool // Mark this object is for in concurrent-safe usage. Tags string // Custom priority tags for decoding. StrNumber bool // StrNumber causes the Decoder to unmarshal a number into an interface{} as a string instead of as a float64. diff --git a/encoding/gjson/gjson_api_new_load.go b/encoding/gjson/gjson_api_new_load.go index 8759f2e71..bd6dcb504 100644 --- a/encoding/gjson/gjson_api_new_load.go +++ b/encoding/gjson/gjson_api_new_load.go @@ -42,22 +42,22 @@ func New(data interface{}, safe ...bool) *Json { // The parameter specifies whether using this Json object in concurrent-safe context, which // is false in default. func NewWithTag(data interface{}, tags string, safe ...bool) *Json { - option := Option{ + option := Options{ Tags: tags, } if len(safe) > 0 && safe[0] { option.Safe = true } - return NewWithOption(data, option) + return NewWithOptions(data, option) } -// NewWithOption creates a Json object with any variable type of , but should be a map +// NewWithOptions creates a Json object with any variable type of , but should be a map // or slice for data access reason, or it will make no sense. -func NewWithOption(data interface{}, option Option) *Json { +func NewWithOptions(data interface{}, options Options) *Json { var j *Json switch data.(type) { case string, []byte: - if r, err := loadContentWithOption(data, option); err == nil { + if r, err := loadContentWithOptions(data, options); err == nil { j = r } else { j = &Json{ @@ -86,7 +86,7 @@ func NewWithOption(data interface{}, option Option) *Json { } case reflect.Map, reflect.Struct: i := interface{}(nil) - i = gconv.MapDeep(data, option.Tags) + i = gconv.MapDeep(data, options.Tags) j = &Json{ p: &i, c: byte(defaultSplitChar), @@ -100,7 +100,7 @@ func NewWithOption(data interface{}, option Option) *Json { } } } - j.mu = rwmutex.New(option.Safe) + j.mu = rwmutex.New(options.Safe) return j } @@ -111,56 +111,56 @@ func Load(path string, safe ...bool) (*Json, error) { } else { path = p } - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption(gfile.Ext(path), gfile.GetBytesWithCache(path), option) + return doLoadContentWithOptions(gfile.Ext(path), gfile.GetBytesWithCache(path), option) } // LoadJson creates a Json object from given JSON format content. func LoadJson(data interface{}, safe ...bool) (*Json, error) { - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption("json", gconv.Bytes(data), option) + return doLoadContentWithOptions("json", gconv.Bytes(data), option) } // LoadXml creates a Json object from given XML format content. func LoadXml(data interface{}, safe ...bool) (*Json, error) { - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption("xml", gconv.Bytes(data), option) + return doLoadContentWithOptions("xml", gconv.Bytes(data), option) } // LoadIni creates a Json object from given INI format content. func LoadIni(data interface{}, safe ...bool) (*Json, error) { - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption("ini", gconv.Bytes(data), option) + return doLoadContentWithOptions("ini", gconv.Bytes(data), option) } // LoadYaml creates a Json object from given YAML format content. func LoadYaml(data interface{}, safe ...bool) (*Json, error) { - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption("yaml", gconv.Bytes(data), option) + return doLoadContentWithOptions("yaml", gconv.Bytes(data), option) } // LoadToml creates a Json object from given TOML format content. func LoadToml(data interface{}, safe ...bool) (*Json, error) { - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption("toml", gconv.Bytes(data), option) + return doLoadContentWithOptions("toml", gconv.Bytes(data), option) } // LoadContent creates a Json object from given content, it checks the data type of @@ -186,11 +186,11 @@ func LoadContentType(dataType string, data interface{}, safe ...bool) (*Json, er if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF { content = content[3:] } - option := Option{} + option := Options{} if len(safe) > 0 && safe[0] { option.Safe = true } - return doLoadContentWithOption(dataType, content, option) + return doLoadContentWithOptions(dataType, content, option) } // IsValidDataType checks and returns whether given a valid data type for loading. @@ -208,36 +208,36 @@ func IsValidDataType(dataType string) bool { return false } -func loadContentWithOption(data interface{}, option Option) (*Json, error) { +func loadContentWithOptions(data interface{}, options Options) (*Json, error) { content := gconv.Bytes(data) if len(content) == 0 { - return NewWithOption(nil, option), nil + return NewWithOptions(nil, options), nil } - return loadContentTypeWithOption(checkDataType(content), content, option) + return loadContentTypeWithOptions(checkDataType(content), content, options) } -func loadContentTypeWithOption(dataType string, data interface{}, option Option) (*Json, error) { +func loadContentTypeWithOptions(dataType string, data interface{}, options Options) (*Json, error) { content := gconv.Bytes(data) if len(content) == 0 { - return NewWithOption(nil, option), nil + return NewWithOptions(nil, options), nil } //ignore UTF8-BOM if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF { content = content[3:] } - return doLoadContentWithOption(dataType, content, option) + return doLoadContentWithOptions(dataType, content, options) } // doLoadContent creates a Json object from given content. // It supports data content type as follows: // JSON, XML, INI, YAML and TOML. -func doLoadContentWithOption(dataType string, data []byte, option Option) (*Json, error) { +func doLoadContentWithOptions(dataType string, data []byte, options Options) (*Json, error) { var ( err error result interface{} ) if len(data) == 0 { - return NewWithOption(nil, option), nil + return NewWithOptions(nil, options), nil } if dataType == "" { dataType = checkDataType(data) @@ -270,7 +270,7 @@ func doLoadContentWithOption(dataType string, data []byte, option Option) (*Json return nil, err } decoder := json.NewDecoder(bytes.NewReader(data)) - if option.StrNumber { + if options.StrNumber { decoder.UseNumber() } if err := decoder.Decode(&result); err != nil { @@ -280,7 +280,7 @@ func doLoadContentWithOption(dataType string, data []byte, option Option) (*Json case string, []byte: return nil, fmt.Errorf(`json decoding failed for content: %s`, string(data)) } - return NewWithOption(result, option), nil + return NewWithOptions(result, options), nil } // checkDataType automatically checks and returns the data type for . @@ -291,7 +291,8 @@ func checkDataType(content []byte) string { return "json" } else if gregex.IsMatch(`^<.+>[\S\s]+<.+>\s*$`, content) { return "xml" - } else if !gregex.IsMatch(`[\n\r]*[\s\t\w\-\."]+\s*=\s*"""[\s\S]+"""`, content) && !gregex.IsMatch(`[\n\r]*[\s\t\w\-\."]+\s*=\s*'''[\s\S]+'''`, content) && + } else if !gregex.IsMatch(`[\n\r]*[\s\t\w\-\."]+\s*=\s*"""[\s\S]+"""`, content) && + !gregex.IsMatch(`[\n\r]*[\s\t\w\-\."]+\s*=\s*'''[\s\S]+'''`, content) && ((gregex.IsMatch(`^[\n\r]*[\w\-\s\t]+\s*:\s*".+"`, content) || gregex.IsMatch(`^[\n\r]*[\w\-\s\t]+\s*:\s*\w+`, content)) || (gregex.IsMatch(`[\n\r]+[\w\-\s\t]+\s*:\s*".+"`, content) || gregex.IsMatch(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, content))) { return "yml" diff --git a/encoding/gjson/gjson_z_unit_basic_test.go b/encoding/gjson/gjson_z_unit_basic_test.go index 733adea8e..c89b615ad 100644 --- a/encoding/gjson/gjson_z_unit_basic_test.go +++ b/encoding/gjson/gjson_z_unit_basic_test.go @@ -474,7 +474,7 @@ func TestJson_Var(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { data := []byte("[9223372036854775807, 9223372036854775806]") - array := gjson.NewWithOption(data, gjson.Option{StrNumber: true}).Var().Array() + array := gjson.NewWithOptions(data, gjson.Options{StrNumber: true}).Var().Array() t.Assert(array, []uint64{9223372036854775807, 9223372036854775806}) }) } diff --git a/encoding/gjson/gjson_z_unit_implements_test.go b/encoding/gjson/gjson_z_unit_implements_test.go index 8264e1625..8350f3a29 100644 --- a/encoding/gjson/gjson_z_unit_implements_test.go +++ b/encoding/gjson/gjson_z_unit_implements_test.go @@ -20,7 +20,7 @@ func TestJson_UnmarshalJSON(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) gtest.C(t, func(t *gtest.T) { j := gjson.New(nil) - err := json.Unmarshal(data, j) + err := json.UnmarshalUseNumber(data, j) t.Assert(err, nil) t.Assert(j.Get("n"), "123456789") t.Assert(j.Get("m"), g.Map{"k": "v"}) diff --git a/encoding/gjson/gjson_z_unit_new_test.go b/encoding/gjson/gjson_z_unit_new_test.go index b4f911379..359cafd64 100644 --- a/encoding/gjson/gjson_z_unit_new_test.go +++ b/encoding/gjson/gjson_z_unit_new_test.go @@ -98,7 +98,7 @@ func Test_New_HierarchicalStruct(t *testing.T) { }) } -func Test_NewWithOption(t *testing.T) { +func Test_NewWithOptions(t *testing.T) { gtest.C(t, func(t *gtest.T) { data := []byte("[9223372036854775807, 9223372036854775806]") array := gjson.New(data).Array() @@ -106,7 +106,7 @@ func Test_NewWithOption(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { data := []byte("[9223372036854775807, 9223372036854775806]") - array := gjson.NewWithOption(data, gjson.Option{StrNumber: true}).Array() + array := gjson.NewWithOptions(data, gjson.Options{StrNumber: true}).Array() t.Assert(array, []uint64{9223372036854775807, 9223372036854775806}) }) } diff --git a/internal/json/json.go b/internal/json/json.go index 1ed12ba79..ae6c38f13 100644 --- a/internal/json/json.go +++ b/internal/json/json.go @@ -8,6 +8,7 @@ package json import ( + "bytes" "encoding/json" "io" ) @@ -33,6 +34,13 @@ func Unmarshal(data []byte, v interface{}) error { return json.Unmarshal(data, v) } +// UnmarshalUseNumber decodes the json data bytes to target interface using number option. +func UnmarshalUseNumber(data []byte, v interface{}) error { + decoder := NewDecoder(bytes.NewReader(data)) + decoder.UseNumber() + return decoder.Decode(v) +} + // NewEncoder same as json.NewEncoder func NewEncoder(writer io.Writer) *json.Encoder { return json.NewEncoder(writer) diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index c9bfdcbec..d79788d65 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -320,7 +320,7 @@ func (r *Request) parseBody() { body = bytes.TrimSpace(body) // JSON format checks. if body[0] == '{' && body[len(body)-1] == '}' { - _ = json.Unmarshal(body, &r.bodyMap) + _ = json.UnmarshalUseNumber(body, &r.bodyMap) } // XML format checks. if len(body) > 5 && bytes.EqualFold(body[:5], xmlHeaderBytes) { diff --git a/net/ghttp/ghttp_unit_request_json_test.go b/net/ghttp/ghttp_unit_request_json_test.go index 09e68c72b..7feb32e52 100644 --- a/net/ghttp/ghttp_unit_request_json_test.go +++ b/net/ghttp/ghttp_unit_request_json_test.go @@ -144,7 +144,7 @@ func Test_Params_Json_Response(t *testing.T) { client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) map1 := make(map[string]interface{}) - err1 := json.Unmarshal([]byte(client.GetContent("/json1")), &map1) + err1 := json.UnmarshalUseNumber([]byte(client.GetContent("/json1")), &map1) t.Assert(err1, nil) t.Assert(len(map1), 4) t.Assert(map1["Name"], "john") @@ -153,7 +153,7 @@ func Test_Params_Json_Response(t *testing.T) { t.Assert(map1["password2"], "456") map2 := make(map[string]interface{}) - err2 := json.Unmarshal([]byte(client.GetContent("/json2")), &map2) + err2 := json.UnmarshalUseNumber([]byte(client.GetContent("/json2")), &map2) t.Assert(err2, nil) t.Assert(len(map2), 4) t.Assert(map2["Name"], "john") @@ -162,14 +162,14 @@ func Test_Params_Json_Response(t *testing.T) { t.Assert(map2["password2"], "456") map3 := make(map[string]interface{}) - err3 := json.Unmarshal([]byte(client.GetContent("/json3")), &map3) + err3 := json.UnmarshalUseNumber([]byte(client.GetContent("/json3")), &map3) t.Assert(err3, nil) t.Assert(len(map3), 2) t.Assert(map3["success"], "true") t.Assert(map3["message"], g.Map{"body": "测试", "code": 3, "error": "error"}) map4 := make(map[string]interface{}) - err4 := json.Unmarshal([]byte(client.GetContent("/json4")), &map4) + err4 := json.UnmarshalUseNumber([]byte(client.GetContent("/json4")), &map4) t.Assert(err4, nil) t.Assert(len(map4), 2) t.Assert(map4["success"], "true") diff --git a/net/gtrace/gtrace_carrier.go b/net/gtrace/gtrace_carrier.go index c0cd41979..997f2ea91 100644 --- a/net/gtrace/gtrace_carrier.go +++ b/net/gtrace/gtrace_carrier.go @@ -55,5 +55,5 @@ func (c Carrier) String() string { func (c Carrier) UnmarshalJSON(b []byte) error { carrier := NewCarrier(nil) - return json.Unmarshal(b, carrier) + return json.UnmarshalUseNumber(b, carrier) } diff --git a/os/gbuild/gbuild.go b/os/gbuild/gbuild.go index 7f5cd6e99..5447c0cb7 100644 --- a/os/gbuild/gbuild.go +++ b/os/gbuild/gbuild.go @@ -24,7 +24,7 @@ var ( func init() { if builtInVarStr != "" { - err := json.Unmarshal(gbase64.MustDecodeString(builtInVarStr), &builtInVarMap) + err := json.UnmarshalUseNumber(gbase64.MustDecodeString(builtInVarStr), &builtInVarMap) if err != nil { intlog.Error(err) } diff --git a/os/gproc/gproc_comm_receive.go b/os/gproc/gproc_comm_receive.go index b0bd9f39a..18a815553 100644 --- a/os/gproc/gproc_comm_receive.go +++ b/os/gproc/gproc_comm_receive.go @@ -89,7 +89,7 @@ func receiveTcpHandler(conn *gtcp.Conn) { if len(buffer) > 0 { // Package decoding. msg := new(MsgRequest) - if err := json.Unmarshal(buffer, msg); err != nil { + if err := json.UnmarshalUseNumber(buffer, msg); err != nil { //glog.Error(err) continue } diff --git a/os/gproc/gproc_comm_send.go b/os/gproc/gproc_comm_send.go index 25af7c453..b53c5132e 100644 --- a/os/gproc/gproc_comm_send.go +++ b/os/gproc/gproc_comm_send.go @@ -43,7 +43,7 @@ func Send(pid int, data []byte, group ...string) error { }) if len(result) > 0 { response := new(MsgResponse) - err = json.Unmarshal(result, response) + err = json.UnmarshalUseNumber(result, response) if err == nil { if response.Code != 1 { err = errors.New(response.Message) diff --git a/os/gsession/gsession_storage_file.go b/os/gsession/gsession_storage_file.go index 51936a499..fb0bc7ca6 100644 --- a/os/gsession/gsession_storage_file.go +++ b/os/gsession/gsession_storage_file.go @@ -175,7 +175,7 @@ func (s *StorageFile) GetSession(id string, ttl time.Duration, data *gmap.StrAny } } var m map[string]interface{} - if err = json.Unmarshal(content, &m); err != nil { + if err = json.UnmarshalUseNumber(content, &m); err != nil { return nil, err } if m == nil { diff --git a/os/gsession/gsession_storage_redis.go b/os/gsession/gsession_storage_redis.go index bd5714e66..8d26e2db6 100644 --- a/os/gsession/gsession_storage_redis.go +++ b/os/gsession/gsession_storage_redis.go @@ -126,7 +126,7 @@ func (s *StorageRedis) GetSession(id string, ttl time.Duration, data *gmap.StrAn return nil, nil } var m map[string]interface{} - if err = json.Unmarshal(content, &m); err != nil { + if err = json.UnmarshalUseNumber(content, &m); err != nil { return nil, err } if m == nil { diff --git a/os/gtime/gtime_z_unit_json_test.go b/os/gtime/gtime_z_unit_json_test.go index b79fd3230..781da86d6 100644 --- a/os/gtime/gtime_z_unit_json_test.go +++ b/os/gtime/gtime_z_unit_json_test.go @@ -50,7 +50,7 @@ func Test_Json_Pointer(t *testing.T) { gtest.C(t, func(t *gtest.T) { var t1 gtime.Time s := []byte(`"2006-01-02 15:04:05"`) - err := json.Unmarshal(s, &t1) + err := json.UnmarshalUseNumber(s, &t1) t.Assert(err, nil) t.Assert(t1.String(), "2006-01-02 15:04:05") }) diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index 5563ddda8..abab585cb 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -56,7 +56,7 @@ func doMapConvert(value interface{}, recursive bool, tags ...string) map[string] case string: // If it is a JSON string, automatically unmarshal it! if len(r) > 0 && r[0] == '{' && r[len(r)-1] == '}' { - if err := json.Unmarshal([]byte(r), &dataMap); err != nil { + if err := json.UnmarshalUseNumber([]byte(r), &dataMap); err != nil { return nil } } else { @@ -65,7 +65,7 @@ func doMapConvert(value interface{}, recursive bool, tags ...string) map[string] case []byte: // If it is a JSON string, automatically unmarshal it! if len(r) > 0 && r[0] == '{' && r[len(r)-1] == '}' { - if err := json.Unmarshal(r, &dataMap); err != nil { + if err := json.UnmarshalUseNumber(r, &dataMap); err != nil { return nil } } else { diff --git a/util/gconv/gconv_maps.go b/util/gconv/gconv_maps.go index 8a05e9600..931b181cf 100644 --- a/util/gconv/gconv_maps.go +++ b/util/gconv/gconv_maps.go @@ -33,7 +33,7 @@ func Maps(value interface{}, tags ...string) []map[string]interface{} { case string: list := make([]map[string]interface{}, 0) if len(r) > 0 && r[0] == '[' && r[len(r)-1] == ']' { - if err := json.Unmarshal([]byte(r), &list); err != nil { + if err := json.UnmarshalUseNumber([]byte(r), &list); err != nil { return nil } return list @@ -44,7 +44,7 @@ func Maps(value interface{}, tags ...string) []map[string]interface{} { case []byte: list := make([]map[string]interface{}, 0) if len(r) > 0 && r[0] == '[' && r[len(r)-1] == ']' { - if err := json.Unmarshal(r, &list); err != nil { + if err := json.UnmarshalUseNumber(r, &list); err != nil { return nil } return list @@ -79,7 +79,7 @@ func MapsDeep(value interface{}, tags ...string) []map[string]interface{} { case string: list := make([]map[string]interface{}, 0) if len(r) > 0 && r[0] == '[' && r[len(r)-1] == ']' { - if err := json.Unmarshal([]byte(r), &list); err != nil { + if err := json.UnmarshalUseNumber([]byte(r), &list); err != nil { return nil } return list @@ -90,7 +90,7 @@ func MapsDeep(value interface{}, tags ...string) []map[string]interface{} { case []byte: list := make([]map[string]interface{}, 0) if len(r) > 0 && r[0] == '[' && r[len(r)-1] == ']' { - if err := json.Unmarshal(r, &list); err != nil { + if err := json.UnmarshalUseNumber(r, &list); err != nil { return nil } return list diff --git a/util/gconv/gconv_maptomap.go b/util/gconv/gconv_maptomap.go index 143d6d013..ded5ea744 100644 --- a/util/gconv/gconv_maptomap.go +++ b/util/gconv/gconv_maptomap.go @@ -36,20 +36,20 @@ func doMapToMap(params interface{}, pointer interface{}, mapping ...map[string]s if json.Valid(r) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(r, rv.Interface()) + return json.UnmarshalUseNumber(r, rv.Interface()) } } else { - return json.Unmarshal(r, pointer) + return json.UnmarshalUseNumber(r, pointer) } } case string: if paramsBytes := []byte(r); json.Valid(paramsBytes) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(paramsBytes, rv.Interface()) + return json.UnmarshalUseNumber(paramsBytes, rv.Interface()) } } else { - return json.Unmarshal(paramsBytes, pointer) + return json.UnmarshalUseNumber(paramsBytes, pointer) } } } diff --git a/util/gconv/gconv_maptomaps.go b/util/gconv/gconv_maptomaps.go index 9e0d58306..f4bebc7dc 100644 --- a/util/gconv/gconv_maptomaps.go +++ b/util/gconv/gconv_maptomaps.go @@ -40,20 +40,20 @@ func doMapToMaps(params interface{}, pointer interface{}, mapping ...map[string] if json.Valid(r) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(r, rv.Interface()) + return json.UnmarshalUseNumber(r, rv.Interface()) } } else { - return json.Unmarshal(r, pointer) + return json.UnmarshalUseNumber(r, pointer) } } case string: if paramsBytes := []byte(r); json.Valid(paramsBytes) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(paramsBytes, rv.Interface()) + return json.UnmarshalUseNumber(paramsBytes, rv.Interface()) } } else { - return json.Unmarshal(paramsBytes, pointer) + return json.UnmarshalUseNumber(paramsBytes, pointer) } } } diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go index 0d4924bd7..06416f863 100644 --- a/util/gconv/gconv_struct.go +++ b/util/gconv/gconv_struct.go @@ -83,20 +83,20 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string if json.Valid(r) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(r, rv.Interface()) + return json.UnmarshalUseNumber(r, rv.Interface()) } } else { - return json.Unmarshal(r, pointer) + return json.UnmarshalUseNumber(r, pointer) } } case string: if paramsBytes := []byte(r); json.Valid(paramsBytes) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(paramsBytes, rv.Interface()) + return json.UnmarshalUseNumber(paramsBytes, rv.Interface()) } } else { - return json.Unmarshal(paramsBytes, pointer) + return json.UnmarshalUseNumber(paramsBytes, pointer) } } } diff --git a/util/gconv/gconv_structs.go b/util/gconv/gconv_structs.go index 89e220ac4..8d3626d36 100644 --- a/util/gconv/gconv_structs.go +++ b/util/gconv/gconv_structs.go @@ -74,20 +74,20 @@ func doStructs(params interface{}, pointer interface{}, mapping map[string]strin if json.Valid(r) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(r, rv.Interface()) + return json.UnmarshalUseNumber(r, rv.Interface()) } } else { - return json.Unmarshal(r, pointer) + return json.UnmarshalUseNumber(r, pointer) } } case string: if paramsBytes := []byte(r); json.Valid(paramsBytes) { if rv, ok := pointer.(reflect.Value); ok { if rv.Kind() == reflect.Ptr { - return json.Unmarshal(paramsBytes, rv.Interface()) + return json.UnmarshalUseNumber(paramsBytes, rv.Interface()) } } else { - return json.Unmarshal(paramsBytes, pointer) + return json.UnmarshalUseNumber(paramsBytes, pointer) } } } diff --git a/util/gconv/gconv_z_unit_struct_test.go b/util/gconv/gconv_z_unit_struct_test.go index 062c17d50..faa79d921 100644 --- a/util/gconv/gconv_z_unit_struct_test.go +++ b/util/gconv/gconv_z_unit_struct_test.go @@ -817,7 +817,7 @@ func Test_Struct_Complex(t *testing.T) { "errorMsg": null }` m := make(g.Map) - err := json.Unmarshal([]byte(data), &m) + err := json.UnmarshalUseNumber([]byte(data), &m) t.Assert(err, nil) model := new(XinYanModel)