on master help sign in
Treat the absence of a Maybe field as Nothing in the GHC Generics code
commit8e4b5be437ba411878086917c47a697641940b1f authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 8 Apr 2013, 00:37 (14 years ago) parentc595a42
1 file changed+7
Data/Aeson/Types/Generic.hs+7
Data/Aeson/Types/Generic.hs+7
@@ -447,6 +447,13 @@ instance (Selector s, GFromJSON a) => GFromRecord (S1 s a) where
447447 key = fieldNameModifier opts $ selName (undefined :: t s a p)
448448 {-# INLINE gParseRecord #-}
449449
450+instance (Selector s, FromJSON a) => GFromRecord (S1 s (K1 i (Maybe a))) where
451+ gParseRecord opts obj = (M1 . K1) <$> obj .:? pack key
452+ where
453+ key = fieldNameModifier opts $
454+ selName (undefined :: t s (K1 i (Maybe a)) p)
455+ {-# INLINE gParseRecord #-}
456+
450457--------------------------------------------------------------------------------
451458
452459class ProductSize f where