@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, GeneralizedNewtypeDeriving,
1{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, GeneralizedNewtypeDeriving,
2− IncoherentInstances, OverlappingInstances, OverloadedStrings, Rank2Types #-}
2+ IncoherentInstances, OverlappingInstances, OverloadedStrings, Rank2Types,
5-- Module: Data.Aeson.Types
6-- Module: Data.Aeson.Types
@@ -325,14 +326,21 @@ instance (FromJSON a) => FromJSON (Maybe a) where
325 {-# INLINE parseJSON #-}
326 {-# INLINE parseJSON #-}
327instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
328instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
328− toJSON (Left a) = toJSON a
329+ toJSON (Left a) = object [left .= a]
329− toJSON (Right b) = toJSON b
330+ toJSON (Right b) = object [right .= b]
330 {-# INLINE toJSON #-}
331 {-# INLINE toJSON #-}
332instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
333instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
334+ parseJSON (Object (M.toList -> [(key, value)]))
335+ | key == left = Left <$> parseJSON value
333− parseJSON a = Left <$> parseJSON a <|> Right <$> parseJSON a
336+ | key == right = Right <$> parseJSON value
334 {-# INLINE parseJSON #-}
338 {-# INLINE parseJSON #-}
336instance ToJSON Bool where
344instance ToJSON Bool where
337 toJSON = Bool
345 toJSON = Bool
338 {-# INLINE toJSON #-}
346 {-# INLINE toJSON #-}