diff --git a/src/Data/Aeson/Types/FromJSON.hs b/src/Data/Aeson/Types/FromJSON.hs index 3f766e43..1f88e3ed 100644 --- a/src/Data/Aeson/Types/FromJSON.hs +++ b/src/Data/Aeson/Types/FromJSON.hs @@ -1452,6 +1452,13 @@ instance {-# OVERLAPPING #-} recordParseJSONImpl (guard (allowOmittedFields opts) >> fmap Par1 o) gParseJSON args obj {-# INLINE recordParseJSON' #-} +instance {-# OVERLAPPING #-} + (Selector s, GFromJSON One (f :.: Rec1 g), FromJSON1 f, FromJSON1 g) => + RecordFromJSON' One (S1 s (f :.: Rec1 g)) where + recordParseJSON' args@(_ :* _ :* opts :* From1Args o _ _) obj = recordParseJSONImpl d gParseJSON args obj where + d = guard (allowOmittedFields opts) >> fmap Comp1 (liftOmittedField (fmap Rec1 (liftOmittedField o))) + {-# INLINE recordParseJSON' #-} + recordParseJSONImpl :: forall s arity a f i . (Selector s) diff --git a/src/Data/Aeson/Types/ToJSON.hs b/src/Data/Aeson/Types/ToJSON.hs index 7de88759..3f4a4f12 100644 --- a/src/Data/Aeson/Types/ToJSON.hs +++ b/src/Data/Aeson/Types/ToJSON.hs @@ -1216,6 +1216,24 @@ instance ( Selector s in key `pair` value {-# INLINE recordToPairs #-} +instance ( Selector s + , GToJSON' enc One (f :.: Rec1 g) + , KeyValuePair enc pairs + , ToJSON1 f + , ToJSON1 g + ) => RecordToPairs enc pairs One (S1 s (f :.: Rec1 g)) + where + recordToPairs opts targs@(To1Args o _ _) m1 + | omitNothingFields opts + , liftOmitField (liftOmitField o . unRec1) $ unComp1 $ unM1 m1 + = mempty + + | otherwise = + let key = Key.fromString $ fieldLabelModifier opts (selName m1) + value = gToJSON opts targs (unM1 m1) + in key `pair` value + {-# INLINE recordToPairs #-} + -------------------------------------------------------------------------------- class WriteProduct arity f where