1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

#12 implement omitempty

This commit is contained in:
Tao Wen
2017-03-08 07:38:25 -08:00
parent ceb8c8a733
commit d1aa59e34e
5 changed files with 150 additions and 10 deletions

View File

@ -158,4 +158,17 @@ func Test_mixed(t *testing.T) {
should.Nil(err)
should.Equal(1, aa.ID)
should.Equal("123", aa.Payload["account"])
}
func Test_omit_empty(t *testing.T) {
should := require.New(t)
type TestObject struct {
Field1 string `json:"field-1,omitempty"`
Field2 string `json:"field-2,omitempty"`
}
obj := TestObject{}
obj.Field2 = "hello"
str, err := MarshalToString(&obj)
should.Nil(err)
should.Equal(`{"field-2":"hello"}`, str)
}