|
|
|
@ -3,6 +3,7 @@ package mapping
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@ -2480,3 +2481,40 @@ func BenchmarkUnmarshal(b *testing.B) {
|
|
|
|
|
UnmarshalKey(data, &an)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderMultiArray(t *testing.T) {
|
|
|
|
|
payload := `{"a": "133", "b": [["add", "cccd"], ["eeee"]]}`
|
|
|
|
|
var res struct {
|
|
|
|
|
A string `json:"a"`
|
|
|
|
|
B [][]string `json:"b"`
|
|
|
|
|
}
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Equal(t, 2, len(res.B))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderPtrMultiArray(t *testing.T) {
|
|
|
|
|
payload := `{"a": "133", "b": [["add", "cccd"], ["eeee"]]}`
|
|
|
|
|
var res struct {
|
|
|
|
|
A string `json:"a"`
|
|
|
|
|
B [][]*string `json:"b"`
|
|
|
|
|
}
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Equal(t, 2, len(res.B))
|
|
|
|
|
assert.Equal(t, 2, len(res.B[0]))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderPtrArray(t *testing.T) {
|
|
|
|
|
payload := `{"a": "133", "b": ["add", "cccd", "eeee"]}`
|
|
|
|
|
var res struct {
|
|
|
|
|
A string `json:"a"`
|
|
|
|
|
B []*string `json:"b"`
|
|
|
|
|
}
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Equal(t, 3, len(res.B))
|
|
|
|
|
}
|
|
|
|
|