@@ -32,7 +32,7 @@ module Data.Aeson.Types.ToJSON
32
32
, toJSON2
33
33
, toEncoding2
34
34
-- * Generic JSON classes
35
- , GToJSON (.. )
35
+ , GToJSON' (.. )
36
36
, ToArgs (.. )
37
37
, genericToJSON
38
38
, genericToEncoding
@@ -155,7 +155,7 @@ realFloatToJSON d
155
155
156
156
-- | Class of generic representation types that can be converted to
157
157
-- JSON.
158
- class GToJSON enc arity f where
158
+ class GToJSON' enc arity f where
159
159
-- | This method (applied to 'defaultOptions') is used as the
160
160
-- default generic implementation of 'toJSON'
161
161
-- (with @enc ~ 'Value'@ and @arity ~ 'Zero'@)
@@ -176,29 +176,29 @@ data ToArgs res arity a where
176
176
-- | A configurable generic JSON creator. This function applied to
177
177
-- 'defaultOptions' is used as the default for 'toJSON' when the type
178
178
-- is an instance of 'Generic'.
179
- genericToJSON :: (Generic a , GToJSON Value Zero (Rep a ))
179
+ genericToJSON :: (Generic a , GToJSON' Value Zero (Rep a ))
180
180
=> Options -> a -> Value
181
181
genericToJSON opts = gToJSON opts NoToArgs . from
182
182
183
183
-- | A configurable generic JSON creator. This function applied to
184
184
-- 'defaultOptions' is used as the default for 'liftToJSON' when the type
185
185
-- is an instance of 'Generic1'.
186
- genericLiftToJSON :: (Generic1 f , GToJSON Value One (Rep1 f ))
186
+ genericLiftToJSON :: (Generic1 f , GToJSON' Value One (Rep1 f ))
187
187
=> Options -> (a -> Value ) -> ([a ] -> Value )
188
188
-> f a -> Value
189
189
genericLiftToJSON opts tj tjl = gToJSON opts (To1Args tj tjl) . from1
190
190
191
191
-- | A configurable generic JSON encoder. This function applied to
192
192
-- 'defaultOptions' is used as the default for 'toEncoding' when the type
193
193
-- is an instance of 'Generic'.
194
- genericToEncoding :: (Generic a , GToJSON Encoding Zero (Rep a ))
194
+ genericToEncoding :: (Generic a , GToJSON' Encoding Zero (Rep a ))
195
195
=> Options -> a -> Encoding
196
196
genericToEncoding opts = gToJSON opts NoToArgs . from
197
197
198
198
-- | A configurable generic JSON encoder. This function applied to
199
199
-- 'defaultOptions' is used as the default for 'liftToEncoding' when the type
200
200
-- is an instance of 'Generic1'.
201
- genericLiftToEncoding :: (Generic1 f , GToJSON Encoding One (Rep1 f ))
201
+ genericLiftToEncoding :: (Generic1 f , GToJSON' Encoding One (Rep1 f ))
202
202
=> Options -> (a -> Encoding ) -> ([a ] -> Encoding )
203
203
-> f a -> Encoding
204
204
genericLiftToEncoding opts te tel = gToJSON opts (To1Args te tel) . from1
@@ -287,7 +287,7 @@ class ToJSON a where
287
287
-- | Convert a Haskell value to a JSON-friendly intermediate type.
288
288
toJSON :: a -> Value
289
289
290
- default toJSON :: (Generic a , GToJSON Value Zero (Rep a )) => a -> Value
290
+ default toJSON :: (Generic a , GToJSON' Value Zero (Rep a )) => a -> Value
291
291
toJSON = genericToJSON defaultOptions
292
292
293
293
-- | Encode a Haskell value as JSON.
@@ -590,7 +590,7 @@ instance GetConName f => GToJSONKey f
590
590
class ToJSON1 f where
591
591
liftToJSON :: (a -> Value ) -> ([a ] -> Value ) -> f a -> Value
592
592
593
- default liftToJSON :: (Generic1 f , GToJSON Value One (Rep1 f ))
593
+ default liftToJSON :: (Generic1 f , GToJSON' Value One (Rep1 f ))
594
594
=> (a -> Value ) -> ([a] -> Value ) -> f a -> Value
595
595
liftToJSON = genericLiftToJSON defaultOptions
596
596
@@ -599,7 +599,7 @@ class ToJSON1 f where
599
599
600
600
liftToEncoding :: (a -> Encoding ) -> ([a ] -> Encoding ) -> f a -> Encoding
601
601
602
- default liftToEncoding :: (Generic1 f , GToJSON Encoding One (Rep1 f ))
602
+ default liftToEncoding :: (Generic1 f , GToJSON' Encoding One (Rep1 f ))
603
603
=> (a -> Encoding ) -> ([a] -> Encoding )
604
604
-> f a -> Encoding
605
605
liftToEncoding = genericLiftToEncoding defaultOptions
@@ -699,12 +699,12 @@ instance (ToJSON a) => ToJSON [a] where
699
699
-- Generic toJSON / toEncoding
700
700
-------------------------------------------------------------------------------
701
701
702
- instance OVERLAPPABLE_ (GToJSON enc arity a ) => GToJSON enc arity (M1 i c a ) where
702
+ instance OVERLAPPABLE_ (GToJSON' enc arity a ) => GToJSON' enc arity (M1 i c a ) where
703
703
-- Meta-information, which is not handled elsewhere, is ignored:
704
704
gToJSON opts targs = gToJSON opts targs . unM1
705
705
{-# INLINE gToJSON #-}
706
706
707
- instance GToJSON enc One Par1 where
707
+ instance GToJSON' enc One Par1 where
708
708
-- Direct occurrences of the last type parameter are encoded with the
709
709
-- function passed in as an argument:
710
710
gToJSON _opts (To1Args tj _) = tj . unPar1
@@ -713,7 +713,7 @@ instance GToJSON enc One Par1 where
713
713
instance ( ConsToJSON enc arity a
714
714
, AllNullary (C1 c a ) allNullary
715
715
, SumToJSON enc arity (C1 c a ) allNullary
716
- ) => GToJSON enc arity (D1 d (C1 c a )) where
716
+ ) => GToJSON' enc arity (D1 d (C1 c a )) where
717
717
-- The option 'tagSingleConstructors' determines whether to wrap
718
718
-- a single-constructor type.
719
719
gToJSON opts targs
@@ -723,15 +723,15 @@ instance ( ConsToJSON enc arity a
723
723
| otherwise = consToJSON opts targs . unM1 . unM1
724
724
{-# INLINE gToJSON #-}
725
725
726
- instance (ConsToJSON enc arity a ) => GToJSON enc arity (C1 c a ) where
726
+ instance (ConsToJSON enc arity a ) => GToJSON' enc arity (C1 c a ) where
727
727
-- Constructors need to be encoded differently depending on whether they're
728
728
-- a record or not. This distinction is made by 'consToJSON':
729
729
gToJSON opts targs = consToJSON opts targs . unM1
730
730
{-# INLINE gToJSON #-}
731
731
732
732
instance ( AllNullary (a :+: b ) allNullary
733
733
, SumToJSON enc arity (a :+: b ) allNullary
734
- ) => GToJSON enc arity (a :+: b )
734
+ ) => GToJSON' enc arity (a :+: b )
735
735
where
736
736
-- If all constructors of a sum datatype are nullary and the
737
737
-- 'allNullaryToStringTag' option is set they are encoded to
@@ -747,31 +747,31 @@ instance ( AllNullary (a :+: b) allNullary
747
747
-- possible but makes error messages a bit harder to understand for missing
748
748
-- instances.
749
749
750
- instance GToJSON Value arity V1 where
750
+ instance GToJSON' Value arity V1 where
751
751
-- Empty values do not exist, which makes the job of formatting them
752
752
-- rather easy:
753
753
gToJSON _ _ x = x `seq` error " case: V1"
754
754
{-# INLINE gToJSON #-}
755
755
756
- instance ToJSON a => GToJSON Value arity (K1 i a ) where
756
+ instance ToJSON a => GToJSON' Value arity (K1 i a ) where
757
757
-- Constant values are encoded using their ToJSON instance:
758
758
gToJSON _opts _ = toJSON . unK1
759
759
{-# INLINE gToJSON #-}
760
760
761
- instance ToJSON1 f => GToJSON Value One (Rec1 f ) where
761
+ instance ToJSON1 f => GToJSON' Value One (Rec1 f ) where
762
762
-- Recursive occurrences of the last type parameter are encoded using their
763
763
-- ToJSON1 instance:
764
764
gToJSON _opts (To1Args tj tjl) = liftToJSON tj tjl . unRec1
765
765
{-# INLINE gToJSON #-}
766
766
767
- instance GToJSON Value arity U1 where
767
+ instance GToJSON' Value arity U1 where
768
768
-- Empty constructors are encoded to an empty array:
769
769
gToJSON _opts _ _ = emptyArray
770
770
{-# INLINE gToJSON #-}
771
771
772
772
instance ( WriteProduct arity a , WriteProduct arity b
773
773
, ProductSize a , ProductSize b
774
- ) => GToJSON Value arity (a :*: b )
774
+ ) => GToJSON' Value arity (a :*: b )
775
775
where
776
776
-- Products are encoded to an array. Here we allocate a mutable vector of
777
777
-- the same size as the product and write the product's elements to it using
@@ -787,8 +787,8 @@ instance ( WriteProduct arity a, WriteProduct arity b
787
787
{-# INLINE gToJSON #-}
788
788
789
789
instance ( ToJSON1 f
790
- , GToJSON Value One g
791
- ) => GToJSON Value One (f :.: g )
790
+ , GToJSON' Value One g
791
+ ) => GToJSON' Value One (f :.: g )
792
792
where
793
793
-- If an occurrence of the last type parameter is nested inside two
794
794
-- composed types, it is encoded by using the outermost type's ToJSON1
@@ -801,25 +801,25 @@ instance ( ToJSON1 f
801
801
--------------------------------------------------------------------------------
802
802
-- Generic toEncoding
803
803
804
- instance ToJSON a => GToJSON Encoding arity (K1 i a ) where
804
+ instance ToJSON a => GToJSON' Encoding arity (K1 i a ) where
805
805
-- Constant values are encoded using their ToJSON instance:
806
806
gToJSON _opts _ = toEncoding . unK1
807
807
{-# INLINE gToJSON #-}
808
808
809
- instance ToJSON1 f => GToJSON Encoding One (Rec1 f ) where
809
+ instance ToJSON1 f => GToJSON' Encoding One (Rec1 f ) where
810
810
-- Recursive occurrences of the last type parameter are encoded using their
811
811
-- ToEncoding1 instance:
812
812
gToJSON _opts (To1Args te tel) = liftToEncoding te tel . unRec1
813
813
{-# INLINE gToJSON #-}
814
814
815
- instance GToJSON Encoding arity U1 where
815
+ instance GToJSON' Encoding arity U1 where
816
816
-- Empty constructors are encoded to an empty array:
817
817
gToJSON _opts _ _ = E. emptyArray_
818
818
{-# INLINE gToJSON #-}
819
819
820
820
instance ( EncodeProduct arity a
821
821
, EncodeProduct arity b
822
- ) => GToJSON Encoding arity (a :*: b )
822
+ ) => GToJSON' Encoding arity (a :*: b )
823
823
where
824
824
-- Products are encoded to an array. Here we allocate a mutable vector of
825
825
-- the same size as the product and write the product's elements to it using
@@ -828,8 +828,8 @@ instance ( EncodeProduct arity a
828
828
{-# INLINE gToJSON #-}
829
829
830
830
instance ( ToJSON1 f
831
- , GToJSON Encoding One g
832
- ) => GToJSON Encoding One (f :.: g )
831
+ , GToJSON' Encoding One g
832
+ ) => GToJSON' Encoding One (f :.: g )
833
833
where
834
834
-- If an occurrence of the last type parameter is nested inside two
835
835
-- composed types, it is encoded by using the outermost type's ToJSON1
@@ -939,7 +939,7 @@ class TaggedObject' enc pairs arity f isRecord where
939
939
taggedObject' :: Options -> ToArgs enc arity a
940
940
-> String -> f a -> Tagged isRecord pairs
941
941
942
- instance ( GToJSON enc arity f
942
+ instance ( GToJSON' enc arity f
943
943
, KeyValuePair enc pairs
944
944
) => TaggedObject' enc pairs arity f False
945
945
where
@@ -994,7 +994,7 @@ instance ( SumToJSON' s enc arity a
994
994
995
995
--------------------------------------------------------------------------------
996
996
997
- instance ( GToJSON Value arity a
997
+ instance ( GToJSON' Value arity a
998
998
, ConsToJSON Value arity a
999
999
, Constructor c
1000
1000
) => SumToJSON' TwoElemArray Value arity (C1 c a ) where
@@ -1007,7 +1007,7 @@ instance ( GToJSON Value arity a
1007
1007
1008
1008
--------------------------------------------------------------------------------
1009
1009
1010
- instance ( GToJSON Encoding arity a
1010
+ instance ( GToJSON' Encoding arity a
1011
1011
, ConsToJSON Encoding arity a
1012
1012
, Constructor c
1013
1013
) => SumToJSON' TwoElemArray Encoding arity (C1 c a )
@@ -1039,7 +1039,7 @@ instance ( IsRecord f isRecord
1039
1039
instance OVERLAPPING_
1040
1040
( RecordToPairs enc pairs arity (S1 s f )
1041
1041
, FromPairs enc pairs
1042
- , GToJSON enc arity f
1042
+ , GToJSON' enc arity f
1043
1043
) => ConsToJSON' enc arity (S1 s f ) True
1044
1044
where
1045
1045
consToJSON' opts targs
@@ -1054,7 +1054,7 @@ instance ( RecordToPairs enc pairs arity f
1054
1054
consToJSON' opts targs = Tagged . fromPairs . recordToPairs opts targs
1055
1055
{-# INLINE consToJSON' #-}
1056
1056
1057
- instance GToJSON enc arity f => ConsToJSON' enc arity f False where
1057
+ instance GToJSON' enc arity f => ConsToJSON' enc arity f False where
1058
1058
consToJSON' opts targs = Tagged . gToJSON opts targs
1059
1059
{-# INLINE consToJSON' #-}
1060
1060
@@ -1080,7 +1080,7 @@ instance ( Monoid pairs
1080
1080
{-# INLINE recordToPairs #-}
1081
1081
1082
1082
instance ( Selector s
1083
- , GToJSON enc arity a
1083
+ , GToJSON' enc arity a
1084
1084
, KeyValuePair enc pairs
1085
1085
) => RecordToPairs enc pairs arity (S1 s a )
1086
1086
where
@@ -1089,7 +1089,7 @@ instance ( Selector s
1089
1089
1090
1090
instance INCOHERENT_
1091
1091
( Selector s
1092
- , GToJSON enc arity (K1 i (Maybe a ))
1092
+ , GToJSON' enc arity (K1 i (Maybe a ))
1093
1093
, KeyValuePair enc pairs
1094
1094
, Monoid pairs
1095
1095
) => RecordToPairs enc pairs arity (S1 s (K1 i (Maybe a )))
@@ -1101,7 +1101,7 @@ instance INCOHERENT_
1101
1101
1102
1102
instance INCOHERENT_
1103
1103
( Selector s
1104
- , GToJSON enc arity (K1 i (Maybe a ))
1104
+ , GToJSON' enc arity (K1 i (Maybe a ))
1105
1105
, KeyValuePair enc pairs
1106
1106
, Monoid pairs
1107
1107
) => RecordToPairs enc pairs arity (S1 s (K1 i (Semigroup. Option a )))
@@ -1113,7 +1113,7 @@ instance INCOHERENT_
1113
1113
{-# INLINE recordToPairs #-}
1114
1114
1115
1115
fieldToPair :: (Selector s
1116
- , GToJSON enc arity a
1116
+ , GToJSON' enc arity a
1117
1117
, KeyValuePair enc pairs )
1118
1118
=> Options -> ToArgs enc arity p
1119
1119
-> S1 s a p -> pairs
@@ -1146,7 +1146,7 @@ instance ( WriteProduct arity a
1146
1146
ixR = ix + lenL
1147
1147
{-# INLINE writeProduct #-}
1148
1148
1149
- instance OVERLAPPABLE_ (GToJSON Value arity a ) => WriteProduct arity a where
1149
+ instance OVERLAPPABLE_ (GToJSON' Value arity a ) => WriteProduct arity a where
1150
1150
writeProduct opts targs mv ix _ =
1151
1151
VM. unsafeWrite mv ix . gToJSON opts targs
1152
1152
{-# INLINE writeProduct #-}
@@ -1169,13 +1169,13 @@ instance ( EncodeProduct arity a
1169
1169
encodeProduct opts targs b
1170
1170
{-# INLINE encodeProduct #-}
1171
1171
1172
- instance OVERLAPPABLE_ (GToJSON Encoding arity a ) => EncodeProduct arity a where
1172
+ instance OVERLAPPABLE_ (GToJSON' Encoding arity a ) => EncodeProduct arity a where
1173
1173
encodeProduct opts targs a = E. retagEncoding $ gToJSON opts targs a
1174
1174
{-# INLINE encodeProduct #-}
1175
1175
1176
1176
--------------------------------------------------------------------------------
1177
1177
1178
- instance ( GToJSON enc arity a
1178
+ instance ( GToJSON' enc arity a
1179
1179
, ConsToJSON enc arity a
1180
1180
, FromPairs enc pairs
1181
1181
, KeyValuePair enc pairs
0 commit comments