Closed randyp closed 6 years ago
I would like your primitive wrappers, such as optional.Bool, to marshal and unmarshal to json accordingly. Right now they are marshaled as objects.
package main import ( "encoding/json" "github.com/markphelps/optional" "os" ) type Foo struct { Bar optional.Bool `json:"bar"` } func main() { json.NewEncoder(os.Stdout).Encode(&Foo{Bar:optional.Bool{}}) // {} json.NewEncoder(os.Stdout).Encode(&Foo{Bar:optional.NewBool(true)}) // {"bar": true} json.NewEncoder(os.Stdout).Encode(&Foo{Bar:optional.NewBool(false)}) // {"bar":false} }
This could be added to the generator template and re-generated the primitive types.
Thanks for the idea @randyp! Checkout the latest version and let me know if that fits your usecase.
I would like your primitive wrappers, such as optional.Bool, to marshal and unmarshal to json accordingly. Right now they are marshaled as objects.