1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

create map if nil

This commit is contained in:
Tao Wen
2017-03-07 18:36:58 -08:00
parent 62028f1ede
commit ceb8c8a733
3 changed files with 39 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package jsoniter
import (
"testing"
"github.com/json-iterator/go/require"
"bytes"
)
func Test_decode_one_field_struct(t *testing.T) {
@ -88,15 +89,15 @@ func Test_decode_five_fields_struct(t *testing.T) {
func Test_decode_ten_fields_struct(t *testing.T) {
should := require.New(t)
type TestObject struct {
field1 string
field2 string
field3 string
field4 string
field5 string
field6 string
field7 string
field8 string
field9 string
field1 string
field2 string
field3 string
field4 string
field5 string
field6 string
field7 string
field8 string
field9 string
field10 string
}
obj := TestObject{}
@ -144,3 +145,17 @@ func Test_write_val_one_field_struct(t *testing.T) {
should.Nil(err)
should.Equal(`{"field-1":"hello"}`, str)
}
func Test_mixed(t *testing.T) {
should := require.New(t)
type AA struct {
ID int `json:"id"`
Payload map[string]interface{} `json:"payload"`
buf *bytes.Buffer `json:"-"`
}
aa := AA{}
err := UnmarshalFromString(` {"id":1, "payload":{"account":"123","password":"456"}}`, &aa)
should.Nil(err)
should.Equal(1, aa.ID)
should.Equal("123", aa.Payload["account"])
}