Skip to content

Commit

Permalink
fix the big number unmarshal error
Browse files Browse the repository at this point in the history
  • Loading branch information
peze committed May 19, 2021
1 parent 6355725 commit fc13b6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ func (err *CastError) Error() string {
// Convert is use convert map[string]interface object to struct
func Convert(in interface{}, out interface{}) error {
byt, _ := json.Marshal(in)
err := jsonParser.Unmarshal(byt, out)
decoder := jsonParser.NewDecoder(bytes.NewReader(byt))
decoder.UseNumber();
err := decoder.Decode(&out)
return err
}

Expand Down
12 changes: 12 additions & 0 deletions tea/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ func TestConvert(t *testing.T) {
utils.AssertEqual(t, "test", string(out.Body))
}

func TestConvertType(t *testing.T){
in := map[string]interface{}{
"key": 123,
"body": []byte("test"),
}
out := new(test)
err := Convert(in, &out)
utils.AssertNil(t, err)
utils.AssertEqual(t, "123", out.Key)
utils.AssertEqual(t, "test", string(out.Body))
}

func TestRuntimeObject(t *testing.T) {
runtimeobject := NewRuntimeObject(nil)
utils.AssertNil(t, runtimeobject.IgnoreSSL)
Expand Down

0 comments on commit fc13b6e

Please sign in to comment.