Skip to content

Commit 4aa5c57

Browse files
徐文平JacksonTian
authored andcommitted
fix json.Unmarshal missing precision
fix json.Unmarshal missing precision fix json.Unmarshal missing precision fix json.Unmarshal missing precision
1 parent 5861658 commit 4aa5c57

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

openapi/commando.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ func (c *Commando) processInvoke(ctx *cli.Context, productCode string, apiOrMeth
173173

174174
func sortJSON(content string) string {
175175
var v interface{}
176-
err := json.Unmarshal([]byte(content), &v)
176+
dec := json.NewDecoder(bytes.NewReader([]byte(content)))
177+
dec.UseNumber()
178+
err := dec.Decode(&v)
177179
if err != nil {
178180
return content
179181
}

openapi/commando_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func Test_processInvoke(t *testing.T) {
215215
out = sortJSON(out)
216216
assert.Equal(t, "{\n\t\"downloadlink\": \"aaa&bbb\"\n}", out)
217217
}
218-
218+
func Test_sortJSON(t *testing.T) {
219+
out := `{"Id":1000000000000000010241024}`
220+
out = sortJSON(out)
221+
assert.Equal(t, "{\n\t\"Id\": 1000000000000000010241024\n}", out)
222+
}
219223
func Test_help(t *testing.T) {
220224
w := new(bytes.Buffer)
221225
stderr := new(bytes.Buffer)

0 commit comments

Comments
 (0)