We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8eb43e commit e658f65Copy full SHA for e658f65
jsoniter_interface_test.go
@@ -351,3 +351,22 @@ func Test_nil_out_null_interface(t *testing.T) {
351
should.Equal(nil, err)
352
should.Equal(nil, obj2.Field)
353
}
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
371
+ should.Equal(string(js), str)
372
+}
0 commit comments