mirror of
https://github.com/json-iterator/go.git
synced 2025-01-23 18:54:21 +02:00
add failing test for handling of nil interface with omitempty
This commit is contained in:
parent
f8eb43eda3
commit
e658f6597a
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user