Skip to content

Speed up default FromJSON/ToJSON instances #335

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Data/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module Data.Aeson
-- ** Generic JSON classes and options
, GFromJSON(..)
, GToJSON(..)
, GToEncoding(..)
, genericToJSON
, genericToEncoding
, genericParseJSON
Expand Down
1 change: 1 addition & 0 deletions Data/Aeson/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Data.Aeson.Types
-- ** Generic JSON classes
, GFromJSON(..)
, GToJSON(..)
, GToEncoding(..)
, genericToJSON
, genericToEncoding
, genericParseJSON
Expand Down
6 changes: 5 additions & 1 deletion Data/Aeson/Types/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Data.Aeson.Types.Class
-- * Generic JSON classes
, GFromJSON(..)
, GToJSON(..)
, GToEncoding(..)
, genericToJSON
, genericToEncoding
, genericParseJSON
Expand All @@ -40,6 +41,9 @@ class GToJSON f where
-- default generic implementation of 'toJSON'.
gToJSON :: Options -> f a -> Value

-- | Class of generic representation types ('Rep') that can be converted to
-- a JSON 'Encoding'.
class GToEncoding f where
-- | This method (applied to 'defaultOptions') can be used as the
-- default generic implementation of 'toEncoding'.
gToEncoding :: Options -> f a -> Encoding
Expand All @@ -59,7 +63,7 @@ genericToJSON opts = gToJSON opts . from
-- | A configurable generic JSON encoder. This function applied to
-- 'defaultOptions' is used as the default for 'toEncoding' when the type
-- is an instance of 'Generic'.
genericToEncoding :: (Generic a, GToJSON (Rep a)) => Options -> a -> Encoding
genericToEncoding :: (Generic a, GToEncoding (Rep a)) => Options -> a -> Encoding
genericToEncoding opts = gToEncoding opts . from

-- | A configurable generic JSON decoder. This function applied to
Expand Down
Loading