toJson should support DateTime fields
jfilby opened this issue · 1 comments
jfilby commented
There could be a parameter that accepts a format string. If this parameter isn't set and a DateTime field is encountered then raise an exception.
This would help to get rid of a lot of data structure wrangling in code that uses this library and uses DateTime fields.
treeform commented
Hey, thank you for raising this issue!
- I don't recommend using DateTimes. Instead, use https://github.com/treeform/chrono. It will serialize nicely without requiring you to give it much thought. The problem with DateTimes is that they contain pointers to procs, which is a peculiar design decision.
- The docs mention how you would write a parse hook for DateTime: https://github.com/treeform/jsony#proc-parsehook-can-be-used-to-do-anything. I'm sure you could figure out a dump hook too.
- I don't want to add DateTime-specific code into Jsony.