Bläddra i källkod

test(object): add test for ignored field on not valid type

Javier Provecho Fernandez 8 år sedan
förälder
incheckning
2c10d8e6bb
1 ändrade filer med 14 tillägg och 0 borttagningar
  1. 14 0
      jsoniter_object_test.go

+ 14 - 0
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 {