-
Notifications
You must be signed in to change notification settings - Fork 454
Open
Description
It may be convenient in some cases to allow omit empty structs when marshalling, for example to save bytes, as default golang unmarshaller does not make difference between empty object and omitted object. So the proposal is to add flag to easyjson generator to allow omit empty structs without breaking default behaviour.
Example:
package types
//go:generate easyjson -allow_omitempty_struct
//easyjson:json
type MyStruct struct {
N MyNestedStruct `json:"n,omitempty"`
}
type MyNestedStruct struct {
A int `json:"a,omitempty"`
B int `json:"b,omitempty"`
}
package main
import "types"
func main() {
b, _ := json.Marshal(types.MyStruct{})
fmt.Println(string(b)) // {}
}
Metadata
Metadata
Assignees
Labels
No labels