@@ -241,11 +241,11 @@ class GFromJSON arity f where
241
241
gParseJSON :: Options -> FromArgs arity a -> Value -> Parser (f a )
242
242
243
243
-- | A 'FromArgs' value either stores nothing (for 'FromJSON') or it stores the
244
- -- two function arguments that decode occurrences of the type parameter (for
244
+ -- three function arguments that decode occurrences of the type parameter (for
245
245
-- 'FromJSON1').
246
246
data FromArgs arity a where
247
247
NoFromArgs :: FromArgs Zero a
248
- From1Args :: (Value -> Parser a ) -> (Value -> Parser [a ]) -> FromArgs One a
248
+ From1Args :: Maybe a -> (Value -> Parser a ) -> (Value -> Parser [a ]) -> FromArgs One a
249
249
250
250
-- | A configurable generic JSON decoder. This function applied to
251
251
-- 'defaultOptions' is used as the default for 'parseJSON' when the
@@ -258,9 +258,9 @@ genericParseJSON opts = fmap to . gParseJSON opts NoFromArgs
258
258
-- 'defaultOptions' is used as the default for 'liftParseJSON' when the
259
259
-- type is an instance of 'Generic1'.
260
260
genericLiftParseJSON :: (Generic1 f , GFromJSON One (Rep1 f ))
261
- => Options -> (Value -> Parser a ) -> (Value -> Parser [a ])
261
+ => Options -> Maybe a -> (Value -> Parser a ) -> (Value -> Parser [a ])
262
262
-> Value -> Parser (f a )
263
- genericLiftParseJSON opts pj pjl = fmap to1 . gParseJSON opts (From1Args pj pjl)
263
+ genericLiftParseJSON opts o pj pjl = fmap to1 . gParseJSON opts (From1Args o pj pjl)
264
264
265
265
-------------------------------------------------------------------------------
266
266
-- Class
@@ -626,7 +626,7 @@ class FromJSON1 f where
626
626
627
627
default liftParseJSON :: (Generic1 f , GFromJSON One (Rep1 f ))
628
628
=> Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
629
- liftParseJSON _ = genericLiftParseJSON defaultOptions
629
+ liftParseJSON = genericLiftParseJSON defaultOptions
630
630
631
631
liftParseJSONList :: Maybe a -> (Value -> Parser a ) -> (Value -> Parser [a ]) -> Value -> Parser [f a ]
632
632
liftParseJSONList o f g v = listParser (liftParseJSON o f g) v
@@ -637,7 +637,7 @@ class FromJSON1 f where
637
637
-- | @since 2.1.0.0
638
638
instance (Generic1 f , GFromJSON One (Rep1 f )) => FromJSON1 (Generically1 f ) where
639
639
liftParseJSON :: forall a . Maybe a -> (Value -> Parser a ) -> (Value -> Parser [a ]) -> Value -> Parser (Generically1 f a )
640
- liftParseJSON _ = coerce (genericLiftParseJSON defaultOptions :: (Value -> Parser a ) -> (Value -> Parser [a ]) -> Value -> Parser (f a ))
640
+ liftParseJSON = coerce (genericLiftParseJSON defaultOptions :: Maybe a -> (Value -> Parser a ) -> (Value -> Parser [a ]) -> Value -> Parser (f a ))
641
641
642
642
-- | Lift the standard 'parseJSON' function through the type constructor.
643
643
parseJSON1 :: (FromJSON1 f , FromJSON a ) => Value -> Parser (f a )
@@ -991,22 +991,25 @@ instance (FromJSON a) => GFromJSON arity (K1 i a) where
991
991
instance GFromJSON One Par1 where
992
992
-- Direct occurrences of the last type parameter are decoded with the
993
993
-- function passed in as an argument:
994
- gParseJSON _opts (From1Args pj _) = fmap Par1 . pj
994
+ gParseJSON _opts (From1Args _ pj _) = fmap Par1 . pj
995
995
{-# INLINE gParseJSON #-}
996
996
997
997
instance (FromJSON1 f ) => GFromJSON One (Rec1 f ) where
998
998
-- Recursive occurrences of the last type parameter are decoded using their
999
999
-- FromJSON1 instance:
1000
- gParseJSON _opts (From1Args pj pjl) = fmap Rec1 . liftParseJSON ( error " TODO " ) pj pjl
1000
+ gParseJSON _opts (From1Args o pj pjl) = fmap Rec1 . liftParseJSON o pj pjl
1001
1001
{-# INLINE gParseJSON #-}
1002
1002
1003
1003
instance (FromJSON1 f , GFromJSON One g ) => GFromJSON One (f :.: g ) where
1004
1004
-- If an occurrence of the last type parameter is nested inside two
1005
1005
-- composed types, it is decoded by using the outermost type's FromJSON1
1006
1006
-- instance to generically decode the innermost type:
1007
+ --
1008
+ -- Note: the ommitedField is not passed here.
1009
+ -- This might be related for :.: associated the wrong way in Generics Rep.
1007
1010
gParseJSON opts fargs =
1008
- let gpj = gParseJSON opts fargs in
1009
- fmap Comp1 . liftParseJSON ( error " TODO " ) gpj (listParser gpj)
1011
+ let gpj = gParseJSON opts fargs
1012
+ in fmap Comp1 . liftParseJSON Nothing gpj (listParser gpj)
1010
1013
{-# INLINE gParseJSON #-}
1011
1014
1012
1015
--------------------------------------------------------------------------------
@@ -1403,21 +1406,30 @@ instance {-# OVERLAPPABLE #-}
1403
1406
instance (Selector s , FromJSON a , Generic a , K1 i a ~ Rep a ) =>
1404
1407
RecordFromJSON' arity (S1 s (K1 i a )) where
1405
1408
recordParseJSON' args@ (_ :* _ :* opts :* _) obj =
1406
- recordParseJSONImpl (fmap K1 $ guard (omitNothingFields opts) >> omittedField) gParseJSON args obj
1409
+ recordParseJSONImpl (guard (omitNothingFields opts) >> fmap K1 omittedField) gParseJSON args obj
1407
1410
{-# INLINE recordParseJSON' #-}
1408
1411
1409
1412
instance {-# OVERLAPPING #-}
1410
1413
(Selector s , FromJSON a ) =>
1411
1414
RecordFromJSON' arity (S1 s (Rec0 a )) where
1412
1415
recordParseJSON' args@ (_ :* _ :* opts :* _) obj =
1413
- recordParseJSONImpl (fmap K1 $ guard (omitNothingFields opts) >> omittedField) gParseJSON args obj
1416
+ recordParseJSONImpl (guard (omitNothingFields opts) >> fmap K1 omittedField) gParseJSON args obj
1414
1417
{-# INLINE recordParseJSON' #-}
1415
1418
1416
- instance (Selector s , GFromJSON arity (Rec1 f ), FromJSON1 f ) =>
1419
+ instance {-# OVERLAPPING #-}
1420
+ (Selector s , GFromJSON arity (Rec1 f ), FromJSON1 f ) =>
1417
1421
RecordFromJSON' arity (S1 s (Rec1 f )) where
1418
1422
recordParseJSON' args obj = recordParseJSONImpl Nothing gParseJSON args obj
1419
1423
{-# INLINE recordParseJSON' #-}
1420
1424
1425
+ instance {-# OVERLAPPING #-}
1426
+ (Selector s , GFromJSON One Par1 ) =>
1427
+ RecordFromJSON' One (S1 s Par1 ) where
1428
+ recordParseJSON' args@ (_ :* _ :* opts :* From1Args o _ _) obj =
1429
+ recordParseJSONImpl (guard (omitNothingFields opts) >> fmap Par1 o) gParseJSON args obj
1430
+ {-# INLINE recordParseJSON' #-}
1431
+
1432
+
1421
1433
recordParseJSONImpl :: forall s arity a f i
1422
1434
. (Selector s )
1423
1435
=> Maybe (f a )
@@ -2358,7 +2370,7 @@ instance (FromJSON a) => FromJSON (Semigroup.WrappedMonoid a) where
2358
2370
2359
2371
#if !MIN_VERSION_base(4,16,0)
2360
2372
instance FromJSON1 Semigroup. Option where
2361
- liftParseJSON p p' = fmap Semigroup. Option . liftParseJSON p p'
2373
+ liftParseJSON o p p' = fmap Semigroup. Option . liftParseJSON o p p'
2362
2374
liftOmittedField _ = Just (Semigroup. Option Nothing )
2363
2375
2364
2376
instance FromJSON a => FromJSON (Semigroup. Option a ) where
0 commit comments