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

support Any as field type

This commit is contained in:
Tao Wen
2017-04-28 09:09:24 +08:00
parent e5476f70e7
commit 8711c74c85
3 changed files with 30 additions and 1 deletions

View File

@ -171,4 +171,17 @@ func Test_omit_empty(t *testing.T) {
str, err := MarshalToString(&obj)
should.Nil(err)
should.Equal(`{"field-2":"hello"}`, str)
}
func Test_any_within_struct(t *testing.T) {
should := require.New(t)
type TestObject struct {
Field1 Any
Field2 Any
}
obj := TestObject{}
err := UnmarshalFromString(`{"Field1": "hello", "Field2": [1,2,3]}`, &obj)
should.Nil(err)
should.Equal("hello", obj.Field1.ToString())
should.Equal("[1,2,3]", obj.Field2.ToString())
}