Re:Go is still not good
by Mawr on Friday August 22, 2025 @05:37PM
(#44990133)
For JSON I just marshall to/from:
For nil, that's interesting. I've never ran into issues there, so I never considered it.
[ Parent
| on HN ]
Ideally, I would want Optional[T] to encode the same as T when a value is present, and to encode in a configurable way when the value is absent. Admittedly, the nothing to null problem exists with *T too, and even with *T and `json:",omitempty"`, you get the opposite problem (null turns to nothing). I didn't think about that at the time, so it's really more of an issue with encoding/json rather than Optional[T] per se. However, you can't implement MarshalJSON and output nothing as far as I know.