-
Notifications
You must be signed in to change notification settings - Fork 329
Description
Suppose I want to encode the following type as JSON using TaggedObject SumEncoding.
data MyType = Zero | One String
deriving (Generic)
instance Aeson.ToJSON MyType
The output of converting One "bla"
to JSON is { "tag": "One", "contents": ["bla"] }
, which is sensible.
However, when converting Zero
to JSON, you get { "tag": "Zero", "contents": [] }
. While technically correct, the "contents" key is completely unnecessary. Worse even, the "contents" key is required for the type to be parsed again.
This is awkward if one wants to use the JSON format as an external interface. Of course, it is possible to manually implement the FromJSON and ToJSON instances for that type, but that is tedious work.
I cannot imagine a case where one would like the empty "contents" key to be there. Is this intended behavior? Is there something I am missing?