Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aeson.toEncoding method implementations not respected #24

Open
TGOlson opened this issue Jun 10, 2017 · 2 comments
Open

Aeson.toEncoding method implementations not respected #24

TGOlson opened this issue Jun 10, 2017 · 2 comments

Comments

@TGOlson
Copy link

TGOlson commented Jun 10, 2017

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.

@giulioforesto
Copy link

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.

@martijnbastiaan
Copy link
Collaborator

Agreed, I'm open to PRs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants