on master help sign in
Remove isUnary
8b007a8Lysxia
Data/Aeson/Types/FromJSON.hs+2−2
@@ -1004,7 +1004,7 @@ instance ( IsRecord f isRecord
1004
1004
1005instance OVERLAPPING_
1005instance OVERLAPPING_
1006 ( GFromJSON arity a, FromRecord arity (S1 s a)
1006 ( GFromJSON arity a, FromRecord arity (S1 s a)
1007− ) => ConsFromJSON' arity (S1 s a) 'True where
1007+ ) => ConsFromJSON' arity (S1 s a) True where
1008 consParseJSON' opts fargs
1008 consParseJSON' opts fargs
1009 | unwrapUnaryRecords opts = Tagged . gParseJSON opts fargs
1009 | unwrapUnaryRecords opts = Tagged . gParseJSON opts fargs
1010 | otherwise = Tagged . withObject "unary record" (parseRecord opts fargs)
1010 | otherwise = Tagged . withObject "unary record" (parseRecord opts fargs)
@@ -1013,7 +1013,7 @@ instance FromRecord arity f => ConsFromJSON' arity f True where
1013 consParseJSON' opts fargs =
1013 consParseJSON' opts fargs =
1014 Tagged . withObject "record (:*:)" (parseRecord opts fargs)
1014 Tagged . withObject "record (:*:)" (parseRecord opts fargs)
1015
1015
1016−instance (GFromJSON arity f) => ConsFromJSON' arity f False where
1016+instance GFromJSON arity f => ConsFromJSON' arity f False where
1017 consParseJSON' opts fargs = Tagged . gParseJSON opts fargs
1017 consParseJSON' opts fargs = Tagged . gParseJSON opts fargs
1018
1018
1019--------------------------------------------------------------------------------
1019--------------------------------------------------------------------------------
Data/Aeson/Types/Generic.hs−5
@@ -44,12 +44,8 @@ import GHC.Generics
44--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
45
45
46class IsRecord (f :: * -> *) isRecord | f -> isRecord
46class IsRecord (f :: * -> *) isRecord | f -> isRecord
47− where
48− isUnary :: f a -> Bool
49− isUnary = const True
50
47
51instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
48instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
52− where isUnary = const False
53#if MIN_VERSION_base(4,9,0)
49#if MIN_VERSION_base(4,9,0)
54instance OVERLAPPING_ IsRecord (M1 S ('MetaSel 'Nothing u ss ds) f) False
50instance OVERLAPPING_ IsRecord (M1 S ('MetaSel 'Nothing u ss ds) f) False
55#else
51#else
@@ -61,7 +57,6 @@ instance IsRecord Par1 True
61instance IsRecord (Rec1 f) True
57instance IsRecord (Rec1 f) True
62instance IsRecord (f :.: g) True
58instance IsRecord (f :.: g) True
63instance IsRecord U1 False
59instance IsRecord U1 False
64− where isUnary = const False
65
60
66--------------------------------------------------------------------------------
61--------------------------------------------------------------------------------
67
62
Data/Aeson/Types/ToJSON.hs+14−10
@@ -956,7 +956,6 @@ class ConsToJSON enc arity f where
956
956
957class ConsToJSON' enc arity f isRecord where
957class ConsToJSON' enc arity f isRecord where
958 consToJSON' :: Options -> ToArgs enc arity a
958 consToJSON' :: Options -> ToArgs enc arity a
959− -> Bool -- ^ Are we a record with one field?
960 -> f a -> Tagged isRecord enc
959 -> f a -> Tagged isRecord enc
961
960
962instance ( IsRecord f isRecord
961instance ( IsRecord f isRecord
@@ -965,23 +964,28 @@ instance ( IsRecord f isRecord
965 where
964 where
966 consToJSON opts targs =
965 consToJSON opts targs =
967 (unTagged :: Tagged isRecord enc -> enc)
966 (unTagged :: Tagged isRecord enc -> enc)
968− . consToJSON' opts targs (isUnary (undefined :: f a))
967+ . consToJSON' opts targs
969 {-# INLINE consToJSON #-}
968 {-# INLINE consToJSON #-}
970
969
970+instance OVERLAPPING_
971−instance ( RecordToPairs enc pairs arity f
971+ ( RecordToPairs enc pairs arity (S1 s f)
972 , FromPairs enc pairs
972 , FromPairs enc pairs
973 , GToJSON enc arity f
973 , GToJSON enc arity f
974− ) => ConsToJSON' enc arity f True
974+ ) => ConsToJSON' enc arity (S1 s f) True
975 where
975 where
976− consToJSON' opts targs isUn =
976+ consToJSON' opts targs
977− Tagged .
978− case (isUn, unwrapUnaryRecords opts) of
977+ | unwrapUnaryRecords opts = Tagged . gToJSON opts targs
979− (True, True) -> gToJSON opts targs
980− _ -> fromPairs . recordToPairs opts targs
978+ | otherwise = Tagged . fromPairs . recordToPairs opts targs
981 {-# INLINE consToJSON' #-}
979 {-# INLINE consToJSON' #-}
982
980
981+instance ( RecordToPairs enc pairs arity f
982+ , FromPairs enc pairs
983+ ) => ConsToJSON' enc arity f True
984+ where
985+ consToJSON' opts targs = Tagged . fromPairs . recordToPairs opts targs
986+
983instance GToJSON enc arity f => ConsToJSON' enc arity f False where
987instance GToJSON enc arity f => ConsToJSON' enc arity f False where
984− consToJSON' opts targs _ = Tagged . gToJSON opts targs
988+ consToJSON' opts targs = Tagged . gToJSON opts targs
985 {-# INLINE consToJSON' #-}
989 {-# INLINE consToJSON' #-}
986
990
987--------------------------------------------------------------------------------
991--------------------------------------------------------------------------------