From 2c10d8e6bbaa06820d1dde9bc6c397de1e429734 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez <javiertitan@gmail.com> Date: Sat, 8 Jul 2017 15:38:27 +0200 Subject: [PATCH] test(object): add test for ignored field on not valid type --- jsoniter_object_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jsoniter_object_test.go b/jsoniter_object_test.go index 031fe17..a50e49d 100644 --- a/jsoniter_object_test.go +++ b/jsoniter_object_test.go @@ -404,6 +404,20 @@ func Test_omit_empty(t *testing.T) { 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) { should := require.New(t) type TestObject struct {