Skip to content

Commit ac6b303

Browse files
committed
Merge pull request #335 from RyanGlScott/master
Speed up default FromJSON/ToJSON instances
2 parents 5c1f3c6 + 991881c commit ac6b303

File tree

5 files changed

+195
-183
lines changed

5 files changed

+195
-183
lines changed

Data/Aeson.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module Data.Aeson
6060
-- ** Generic JSON classes and options
6161
, GFromJSON(..)
6262
, GToJSON(..)
63+
, GToEncoding(..)
6364
, genericToJSON
6465
, genericToEncoding
6566
, genericParseJSON

Data/Aeson/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module Data.Aeson.Types
3939
-- ** Generic JSON classes
4040
, GFromJSON(..)
4141
, GToJSON(..)
42+
, GToEncoding(..)
4243
, genericToJSON
4344
, genericToEncoding
4445
, genericParseJSON

Data/Aeson/Types/Class.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Data.Aeson.Types.Class
1919
-- * Generic JSON classes
2020
, GFromJSON(..)
2121
, GToJSON(..)
22+
, GToEncoding(..)
2223
, genericToJSON
2324
, genericToEncoding
2425
, genericParseJSON
@@ -40,6 +41,9 @@ class GToJSON f where
4041
-- default generic implementation of 'toJSON'.
4142
gToJSON :: Options -> f a -> Value
4243

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

6569
-- | A configurable generic JSON decoder. This function applied to

0 commit comments

Comments
 (0)