aeson-pretty
aeson-pretty copied to clipboard
Aeson.toEncoding method implementations not respected
It doesn't appear that encodePretty
or any of the other variants of that function respect custom encoding options defined in toEncoding
.
Small example:
data Person = Person
{ _name :: Text
, _age :: Int
} deriving (Generic, Show)
instance ToJSON Blockchain where
toEncoding = genericToEncoding $ defaultOptions { fieldLabelModifier = stripUnderscorePrefix }
where stripUnderscorePrefix = ...
Using encode
on this data type, I correctly get {"name": ..., "age": ...}
. But using encodePretty
instead gives me {"_name": ..., "_age": ...}
.
I think this is because the underlying encodePrettyToTextBuilder'
calls toJSON
directly, which does not apply the encoding options. If possible, it'd be great to preserve the options when using encodePretty
.
On top of that, the documentation is misleading:
encodePretty :: ToJSON a => a -> ByteString
A drop-in replacement for aeson's encode function
One would then expect that it uses the same function as encode
, which is toEncoding
, whereas encodePretty
uses toJSON
. The name *encode*Pretty
is misleading too.
Agreed, I'm open to PRs!