You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-24 23:16:47 +02:00
test(object): add test for ignored field on not valid type
This commit is contained in:
@ -404,6 +404,20 @@ func Test_omit_empty(t *testing.T) {
|
|||||||
should.Equal(`{"field-2":"hello"}`, str)
|
should.Equal(`{"field-2":"hello"}`, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ignore_field_on_not_valid_type(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
type TestObject struct {
|
||||||
|
Field1 string `json:"field-1,omitempty"`
|
||||||
|
Field2 func() `json:"-"`
|
||||||
|
}
|
||||||
|
obj := TestObject{}
|
||||||
|
obj.Field1 = "hello world"
|
||||||
|
obj.Field2 = func() {}
|
||||||
|
str, err := MarshalToString(&obj)
|
||||||
|
should.Nil(err)
|
||||||
|
should.Equal(`{"field-1":"hello world"}`, str)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_recursive_struct(t *testing.T) {
|
func Test_recursive_struct(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
type TestObject struct {
|
type TestObject struct {
|
||||||
|
Reference in New Issue
Block a user