francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

Doesn't respect omitempty on basic types #49

Closed veqryn closed 6 years ago

veqryn commented 6 years ago
type Stuff struct {
    Thing string `json:"thing,omitempty"`
}

Unfortunately the above struct still has its field marshaled even when it is empty.

francoispqt commented 6 years ago

Gojay does not work with json tags and does not rely on reflection.

It uses methods on decoder/encoder to marshal/unmarshal properties, I suggest you read documentation first.

If you want to do omit empty you can use the omit empty methods on the Encoder. e.g:

func (t *SomeType) MarshalJSONObject(enc *gojay.Encoder) {
    enc.StringKeyOmitEmpty("someString", t.someString)
}
veqryn commented 6 years ago

@francoispqt shouldn't the code generation tool support this then?