haskell - Aeson's deriveJSON doesn't work as expected for enums -
i write own tojson , fromjson instances, decided use derivejson type because simple:
data priority = high | medium | low deriving show $(derivetojson id ''priority)  main = bs.putstrln . encode $ high   i would've expected json derivation write out enum string. instead, it's key hash! {"high":[]}
why default behavior?
it's because aeson doesn't distinguish between sum types priority , more sophisticated types data priorityanddetails = high { highreason :: text, alerttype :: alert } | medium { personresponsible :: person } | low. fundamentally each of these types "just data constructor n arguments".
in priority high, med, , low each data constructors 0 arguments. in priorityanddetails high, med, , low each data constructors number of named arguments, 2, 1, , 0 respectively.
generally i've found you're need create own tojson , fromjson instances besides prototyping.
Comments
Post a Comment