safe-json
safe-json copied to clipboard
Add optional 'safeToEncoding' method on 'SafeJSON'
I could open a PR for this, but I figured a discussion might be better first.
Right now there's no way to use aeson
's faster toEncoding
JSON serialization methods (if they're defined) with safe-json
.
As far as I can tell, it should be possible to add support for this with a new method on SafeJSON
where a -> Contained Encoding
. It could be optional (like aeson
), with the default
implementation calling safeTo
encoding the resulting Value
.
It gets a bit tricky with something like .=$
, though. I imagine we would need to define a SafeKeyValue
class so that .=$
could use safeToJSON
on Pair
and Object
types, but safeToEncoding
(or whatever it might be called) on Series
types.
I'm not against this addition, in principle.
As I understand it, the SafeKeyValue
class wouldn't be something users of this library would have to define, right? It would just get instances of Pair
, Object
and Series
?
If you'd like to make a PR, that's fine. We'll figure out the ergonomics when there's something tangible. I don't think it should be too difficult.
My suggestion would be to call the method safeEncoding
and the function that uses that encoding and adds the version tag safeToEncoding
.
(REMINDER: make Data.Aeson.Safe.encode
and Data.Aeson.Safe.encodeFile
use the new safeToEncoding
)