Created
April 8, 2018 16:18
-
-
Save nkaretnikov/205f90922f11c94936f2924e1ec3c2ee to your computer and use it in GitHub Desktop.
aeson weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
The issue is that with
toJSON
_
is not removed for fields.