Skip to content

Commit e658f65

Browse files
committed
add failing test for handling of nil interface with omitempty
1 parent f8eb43e commit e658f65

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

jsoniter_interface_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,22 @@ func Test_nil_out_null_interface(t *testing.T) {
351351
should.Equal(nil, err)
352352
should.Equal(nil, obj2.Field)
353353
}
354+
355+
func Test_omitempty_nil_interface(t *testing.T) {
356+
type TestData struct {
357+
Field interface{} `json:"field,omitempty"`
358+
}
359+
should := require.New(t)
360+
361+
obj := TestData{
362+
Field: nil,
363+
}
364+
365+
js, err := json.Marshal(obj)
366+
should.Equal(nil, err)
367+
should.Equal("{}", string(js))
368+
369+
str, err := MarshalToString(obj)
370+
should.Equal(nil, err)
371+
should.Equal(string(js), str)
372+
}

0 commit comments

Comments
 (0)