Skip to content

Instantly share code, notes, and snippets.

@nkaretnikov
Created April 8, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkaretnikov/205f90922f11c94936f2924e1ec3c2ee to your computer and use it in GitHub Desktop.
Save nkaretnikov/205f90922f11c94936f2924e1ec3c2ee to your computer and use it in GitHub Desktop.
aeson weirdness
customOptions :: Options
customOptions = defaultOptions
{ fieldLabelModifier = tail
, constructorTagModifier = map toLower
, unwrapUnaryRecords = True
}
data Auth = Auth
{ _username :: String
, _password :: String
} deriving (Generic, Show)
instance ToJSON Auth where
toEncoding = genericToEncoding customOptions
instance FromJSON Auth where
parseJSON = genericParseJSON customOptions
-- res <- post url (toJSON auth)
-- vs.
-- res <- post url (encode auth)
@nkaretnikov
Copy link
Author

The issue is that with toJSON _ is not removed for fields.

@nkaretnikov
Copy link
Author

And it's a (minor) pain because with encode I'll need to send Content-Type myself since it's just a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment