on master help sign in
Merge
commit47c42826e598660030440101e9c34e5985b03227 authorBryan O'Sullivan <bos@serpentine.com> dateSun 10 May 2015, 23:32 (11 years ago) parenta606347fc87729
1 file changed+19
Data/Aeson/Types/Instances.hs+19
Data/Aeson/Types/Instances.hs+19
@@ -64,6 +64,8 @@ import Data.Scientific (Scientific)
6464import qualified Data.Scientific as Scientific (coefficient, base10Exponent, fromFloatDigits, toRealFloat)
6565import Data.Attoparsec.Number (Number(..))
6666import Data.Fixed
67+import Data.Foldable (toList)
68+import Data.Functor.Identity (Identity(..))
6769import Data.Hashable (Hashable(..))
6870import Data.Int (Int8, Int16, Int32, Int64)
6971import Data.Maybe (fromMaybe)
@@ -87,6 +89,7 @@ import qualified Data.IntMap as IntMap
8789import qualified Data.IntSet as IntSet
8890import qualified Data.Map as M
8991import qualified Data.Set as Set
92+import qualified Data.Sequence as Seq
9093import qualified Data.Tree as Tree
9194import qualified Data.Text as T
9295import qualified Data.Text.Lazy as LT
@@ -97,6 +100,14 @@ import qualified Data.Vector.Storable as VS
97100import qualified Data.Vector.Unboxed as VU
98101import qualified Data.Vector.Mutable as VM ( unsafeNew, unsafeWrite )
99102
103+instance (ToJSON a) => ToJSON (Identity a) where
104+ toJSON (Identity a) = toJSON a
105+ {-# INLINE toJSON #-}
106+
107+instance (FromJSON a) => FromJSON (Identity a) where
108+ parseJSON a = Identity <$> parseJSON a
109+ {-# INLINE parseJSON #-}
110+
100111instance (ToJSON a) => ToJSON (Maybe a) where
101112 toJSON (Just a) = toJSON a
102113 toJSON Nothing = Null
@@ -339,6 +350,14 @@ instance (FromJSON a) => FromJSON [a] where
339350 parseJSON = withArray "[a]" $ mapM parseJSON . V.toList
340351 {-# INLINE parseJSON #-}
341352
353+instance (ToJSON a) => ToJSON (Seq.Seq a) where
354+ toJSON = toJSON . toList
355+ {-# INLINE toJSON #-}
356+
357+instance (FromJSON a) => FromJSON (Seq.Seq a) where
358+ parseJSON = withArray "Seq a" $ traverse parseJSON . Seq.fromList . V.toList
359+ {-# INLINE parseJSON #-}
360+
342361instance (ToJSON a) => ToJSON (Vector a) where
343362 toJSON = Array . V.map toJSON
344363 {-# INLINE toJSON #-}