type Record struct {
TS int64 `json:"ts,omitempty"` // Timestamp in seconds
RID string `json:"rid,omitempty"` // R-ID
}
Gives this generated code:
func (v *Record) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
switch k {
case "tS":
return dec.Int64(&v.TS)
case "rID":
return dec.String(&v.RID)
}
return nil
}
func (v *Record) MarshalJSONObject(enc *gojay.Encoder) {
enc.Int64Key("tS", v.TS)
enc.StringKey("rID", v.RID)
}
When it should give:
func (v *Record) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
switch k {
case "tS":
return dec.Int64(&v.TS)
case "rID":
return dec.String(&v.RID)
}
return nil
}
func (v *Record) MarshalJSONObject(enc *gojay.Encoder) {
enc.Int64Key("ts", v.TS)
enc.StringKeyOmitEmpty("rid", v.RID)
}
The code generator should be pulling the json tag and parsing it to determine the correct key string, as well as other things like omitempty, or fields to skip (-).
This example code:
Gives this generated code:
When it should give:
The code generator should be pulling the
json
tag and parsing it to determine the correct key string, as well as other things likeomitempty
, or fields to skip (-
).