@@ -976,7 +976,7 @@ instance ( IsRecord f isRecord
976
976
977
977
instance (FromRecord arity f ) => FromTaggedObject'' arity f True where
978
978
parseFromTaggedObject'' opts fargs _ =
979
- Tagged . parseRecord opts fargs Nothing
979
+ Tagged . parseRecord opts fargs
980
980
981
981
instance (GFromJSON arity f ) => FromTaggedObject'' arity f False where
982
982
parseFromTaggedObject'' opts fargs contentsFieldName = Tagged .
@@ -993,65 +993,60 @@ class ConsFromJSON arity f where
993
993
994
994
class ConsFromJSON' arity f isRecord where
995
995
consParseJSON' :: Options -> FromArgs arity a
996
- -> Maybe Text -- ^ A dummy label
997
- -- (Nothing to use proper label)
998
996
-> Value -> Tagged isRecord (Parser (f a ))
999
997
1000
998
instance ( IsRecord f isRecord
1001
999
, ConsFromJSON' arity f isRecord
1002
1000
) => ConsFromJSON arity f where
1003
- consParseJSON opts fargs v = let
1004
- (v2,lab) = case (unwrapUnaryRecords opts,isUnary (undefined :: f a )) of
1005
- -- use a dummy object with a dummy label
1006
- (True ,True ) -> (object [(pack " dummy" ,v)], Just $ pack " dummy" )
1007
- _ -> (v,Nothing )
1008
- in (unTagged :: Tagged isRecord (Parser (f a )) -> Parser (f a ))
1009
- $ consParseJSON' opts fargs lab v2
1001
+ consParseJSON opts fargs =
1002
+ (unTagged :: Tagged isRecord (Parser (f a )) -> Parser (f a ))
1003
+ . consParseJSON' opts fargs
1010
1004
1005
+ instance OVERLAPPING_
1006
+ ( GFromJSON arity a , FromRecord arity (S1 s a )
1007
+ ) => ConsFromJSON' arity (S1 s a ) True where
1008
+ consParseJSON' opts fargs
1009
+ | unwrapUnaryRecords opts = Tagged . gParseJSON opts fargs
1010
+ | otherwise = Tagged . withObject " unary record" (parseRecord opts fargs)
1011
1011
1012
- instance ( FromRecord arity f ) => ConsFromJSON' arity f True where
1013
- consParseJSON' opts fargs mlab = Tagged . withObject " record (:*:) "
1014
- (parseRecord opts fargs mlab )
1012
+ instance FromRecord arity f => ConsFromJSON' arity f True where
1013
+ consParseJSON' opts fargs =
1014
+ Tagged . withObject " record (:*:) " (parseRecord opts fargs)
1015
1015
1016
- instance ( GFromJSON arity f ) => ConsFromJSON' arity f False where
1017
- consParseJSON' opts fargs _ = Tagged . gParseJSON opts fargs
1016
+ instance GFromJSON arity f => ConsFromJSON' arity f False where
1017
+ consParseJSON' opts fargs = Tagged . gParseJSON opts fargs
1018
1018
1019
1019
--------------------------------------------------------------------------------
1020
1020
1021
1021
class FromRecord arity f where
1022
1022
parseRecord :: Options -> FromArgs arity a
1023
- -> Maybe Text -- ^ A dummy label
1024
- -- (Nothing to use proper label)
1025
1023
-> Object -> Parser (f a )
1026
1024
1027
1025
instance ( FromRecord arity a
1028
1026
, FromRecord arity b
1029
1027
) => FromRecord arity (a :*: b ) where
1030
- parseRecord opts fargs _ obj =
1031
- (:*:) <$> parseRecord opts fargs Nothing obj
1032
- <*> parseRecord opts fargs Nothing obj
1028
+ parseRecord opts fargs obj =
1029
+ (:*:) <$> parseRecord opts fargs obj
1030
+ <*> parseRecord opts fargs obj
1033
1031
1034
1032
instance OVERLAPPABLE_ (Selector s , GFromJSON arity a ) =>
1035
1033
FromRecord arity (S1 s a ) where
1036
- parseRecord opts fargs lab =
1034
+ parseRecord opts fargs =
1037
1035
(<?> Key label) . gParseJSON opts fargs <=< (.: label)
1038
1036
where
1039
- label = fromMaybe defLabel lab
1040
- defLabel = pack . fieldLabelModifier opts $
1041
- selName (undefined :: t s a p )
1037
+ label = pack . fieldLabelModifier opts $ selName (undefined :: t s a p )
1042
1038
1043
1039
instance INCOHERENT_ (Selector s , FromJSON a ) =>
1044
1040
FromRecord arity (S1 s (K1 i (Maybe a ))) where
1045
- parseRecord _ _ (Just lab) obj = M1 . K1 <$> obj .:? lab
1046
- parseRecord opts _ Nothing obj = M1 . K1 <$> obj .:? pack label
1041
+ parseRecord opts _ obj = M1 . K1 <$> obj .:? pack label
1047
1042
where
1048
1043
label = fieldLabelModifier opts $
1049
1044
selName (undefined :: t s (K1 i (Maybe a )) p )
1050
1045
1051
1046
-- Parse an Option like a Maybe.
1052
1047
instance INCOHERENT_ (Selector s , FromJSON a ) =>
1053
1048
FromRecord arity (S1 s (K1 i (Semigroup. Option a ))) where
1054
- parseRecord opts fargs lab obj = wrap <$> parseRecord opts fargs lab obj
1049
+ parseRecord opts fargs obj = wrap <$> parseRecord opts fargs obj
1055
1050
where
1056
1051
wrap :: S1 s (K1 i (Maybe a )) p -> S1 s (K1 i (Semigroup. Option a )) p
1057
1052
wrap (M1 (K1 a)) = M1 (K1 (Semigroup. Option a))
0 commit comments