Commits

Nikita Volkov  committed 4eef4d8

Fix the Maybe being treated as ADT in Generics bug

  • Participants
  • Parent commits fbfa8d7

Comments (0)

Files changed (1)

File Data/Aeson/Generic.hs

 
 toJSON :: (Data a) => a -> Value
 toJSON = toJSON_generic
+         `ext1Q` maybe
          `ext1Q` list
          `ext1Q` vector
          `ext1Q` set
          `extQ` (T.toJSON :: T ())
          --`extQ` (T.toJSON :: T Ordering)
   where
+    maybe (Just a) = toJSON a
+    maybe Nothing = Null
     list xs = Array . V.fromList . map toJSON $ xs
     vector v = Array . V.map toJSON $ v
     set s = Array . V.fromList . map toJSON . Set.toList $ s
 
 parseJSON :: (Data a) => Value -> Parser a
 parseJSON j = parseJSON_generic j
+             `ext1R` maybeP
              `ext1R` list
              `ext1R` vector
              `ext2R'` mapAny
   where
     value :: (T.FromJSON a) => Parser a
     value = T.parseJSON j
+    maybeP :: (Data a) => Parser (Maybe a)
+    maybeP = if j == Null then return Nothing else Just <$> parseJSON j
     list :: (Data a) => Parser [a]
     list = V.toList <$> parseJSON j
     vector :: (Data a) => Parser (V.Vector a)