mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
fix: wrong way of Unmarshal (#4397)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/jsonx"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -4868,14 +4869,27 @@ func TestUnmarshal_EnvWithOptionsWrongValueString(t *testing.T) {
|
||||
|
||||
func TestUnmarshalJsonReaderMultiArray(t *testing.T) {
|
||||
t.Run("reader multi array", func(t *testing.T) {
|
||||
var res struct {
|
||||
type testRes struct {
|
||||
A string `json:"a"`
|
||||
B [][]string `json:"b"`
|
||||
C []byte `json:"c"`
|
||||
}
|
||||
payload := `{"a": "133", "b": [["add", "cccd"], ["eeee"]]}`
|
||||
var res testRes
|
||||
marshal := testRes{
|
||||
A: "133",
|
||||
B: [][]string{
|
||||
{"add", "cccd"},
|
||||
{"eeee"},
|
||||
},
|
||||
C: []byte("11122344wsss"),
|
||||
}
|
||||
bytes, err := jsonx.Marshal(marshal)
|
||||
assert.NoError(t, err)
|
||||
payload := string(bytes)
|
||||
reader := strings.NewReader(payload)
|
||||
if assert.NoError(t, UnmarshalJsonReader(reader, &res)) {
|
||||
assert.Equal(t, 2, len(res.B))
|
||||
assert.Equal(t, string(marshal.C), string(res.C))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user