You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-24 23:16:47 +02:00
#63 support decode anonymous struct
This commit is contained in:
@ -293,7 +293,7 @@ func Test_one_field_struct(t *testing.T) {
|
||||
should.Equal(`{"Me":{"Field":{"Field":{"Field":"abc"}}}}`, str)
|
||||
}
|
||||
|
||||
func Test_anonymous_struct_marshal(t *testing.T) {
|
||||
func Test_encode_anonymous_struct(t *testing.T) {
|
||||
should := require.New(t)
|
||||
type TestObject struct {
|
||||
Field string
|
||||
@ -308,6 +308,21 @@ func Test_anonymous_struct_marshal(t *testing.T) {
|
||||
should.Equal(`{"Field":100}`, str)
|
||||
}
|
||||
|
||||
func Test_decode_anonymous_struct(t *testing.T) {
|
||||
should := require.New(t)
|
||||
type Inner struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type Outer struct {
|
||||
Inner
|
||||
}
|
||||
var outer Outer
|
||||
j := []byte("{\"key\":\"value\"}")
|
||||
should.Nil(Unmarshal(j, &outer))
|
||||
should.Equal("value", outer.Key)
|
||||
}
|
||||
|
||||
func Test_decode_nested(t *testing.T) {
|
||||
type StructOfString struct {
|
||||
Field1 string
|
||||
|
Reference in New Issue
Block a user