fjl / gencodec

Command gencodec generates marshaling methods for Go struct types.
MIT License
55 stars 27 forks source link

Perhaps correlate `optional` with `omitempty` #1

Open karalabe opened 7 years ago

karalabe commented 7 years ago

Currently there seems to be no correlation between this package's optional tag and for example the json omitempty tag. I.e. if I specify a field in this package to be optional, I'd expect it to automatically add omitempty to json fields and not just blindly copy the original tags. This would be beneficial because it would avoid needing to specify both optional and omitempty.

Now I do know that optional is used during unmarshaling and omitempty during marshaling, so there is a case for the current behavior too. Just figured I'd raise this since I slipped up on this at my first go.