Browse Source

add failing test for handling of nil interface with omitempty

Jason Toffaletti 8 years ago
parent
commit
e658f6597a
1 changed files with 19 additions and 0 deletions
  1. 19 0
      jsoniter_interface_test.go

+ 19 - 0
jsoniter_interface_test.go

@@ -351,3 +351,22 @@ func Test_nil_out_null_interface(t *testing.T) {
 	should.Equal(nil, err)
 	should.Equal(nil, obj2.Field)
 }
+
+func Test_omitempty_nil_interface(t *testing.T) {
+	type TestData struct {
+		Field interface{} `json:"field,omitempty"`
+	}
+	should := require.New(t)
+
+	obj := TestData{
+		Field: nil,
+	}
+
+	js, err := json.Marshal(obj)
+	should.Equal(nil, err)
+	should.Equal("{}", string(js))
+
+	str, err := MarshalToString(obj)
+	should.Equal(nil, err)
+	should.Equal(string(js), str)
+}