You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to be able to omit objects from encoding that are of some custom type. For instance
type Name struct {
First string `json:"first,omitempty"`
Last string `json:"last,omitempty"`
}
type Person struct {
Name Name `json:"name,omitempty"`
Age int `json:"age"`
}
p := Person{
Age: 42,
}
b, _ := json.Marshal(p)
fmt.Println(string(b))
Ideally that would print
{"age":42}
but instead it prints
{"name":{},"age":42}
What would be nice would be to have an interface, json.Empty, which could be used to determine if the value is empty or not.
It would be nice to be able to omit objects from encoding that are of some custom type. For instance
Ideally that would print
but instead it prints
What would be nice would be to have an interface,
json.Empty
, which could be used to determine if the value is empty or not.The check for this could then just be another case added to
json.isEmptyValue()
The text was updated successfully, but these errors were encountered: