@@ -325,12 +325,19 @@ instance (FromJSON a) => FromJSON (Maybe a) where
325 {-# INLINE parseJSON #-}
325 {-# INLINE parseJSON #-}
327instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
327instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
328− toJSON (Left a) = toJSON a
328+ toJSON (Left a) = Array (V.fromList [String "Left", toJSON a])
329− toJSON (Right b) = toJSON b
329+ toJSON (Right b) = Array (V.fromList [String "Right", toJSON b])
330 {-# INLINE toJSON #-}
330 {-# INLINE toJSON #-}
332instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
332instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
333+ parseJSON v@(Array vec) =
334+ if V.length vec /= 2
335+ then typeMismatch "Either a b" v
336+ else case vec V.! 0 of
337+ "Left" -> Left <$> parseJSON (vec V.! 1)
333− parseJSON a = Left <$> parseJSON a <|> Right <$> parseJSON a
338+ "Right" -> Right <$> parseJSON (vec V.! 1)
339+ _ -> typeMismatch "Either a b" v
340+ parseJSON v = typeMismatch "Either a b" v
334 {-# INLINE parseJSON #-}
341 {-# INLINE parseJSON #-}
336instance ToJSON Bool where
343instance ToJSON Bool where