on master help sign in
Merge pull request #359 from neongreen/master
9cfdabbAdam Bergmark
Data/Aeson/Types/Instances.hs+3−1
@@ -511,7 +511,9 @@ instance (ToJSON a) => ToJSON (Seq.Seq a) where
511 {-# INLINE toEncoding #-}
511 {-# INLINE toEncoding #-}
512
512
513instance (FromJSON a) => FromJSON (Seq.Seq a) where
513instance (FromJSON a) => FromJSON (Seq.Seq a) where
514− parseJSON = withArray "Seq a" $ traverse parseJSON . Seq.fromList . V.toList
514+ parseJSON = withArray "Seq a" $
515+ fmap Seq.fromList .
516+ Tr.sequence . zipWith parseIndexedJSON [0..] . V.toList
515 {-# INLINE parseJSON #-}
517 {-# INLINE parseJSON #-}
516
518
517instance (ToJSON a) => ToJSON (Vector a) where
519instance (ToJSON a) => ToJSON (Vector a) where
tests/UnitTests.hs+14
@@ -14,6 +14,7 @@ import Data.Char (toUpper)
14import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
15import Data.Time (UTCTime)
15import Data.Time (UTCTime)
16import Data.Time.Format (parseTime)
16import Data.Time.Format (parseTime)
17+import Data.Sequence (Seq)
17import GHC.Generics (Generic)
18import GHC.Generics (Generic)
18import Test.Framework (Test, testGroup)
19import Test.Framework (Test, testGroup)
19import Test.Framework.Providers.HUnit (testCase)
20import Test.Framework.Providers.HUnit (testCase)
@@ -57,6 +58,7 @@ tests = testGroup "unit" [
57 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
58 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
58 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
59 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
59 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
60 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
61+ , testGroup "JSONPath" $ fmap (testCase "-") jsonPath
60 , testGroup "Issue #351" $ fmap (testCase "-") issue351
62 , testGroup "Issue #351" $ fmap (testCase "-") issue351
61 ]
63 ]
62
64
@@ -231,6 +233,18 @@ jsonDecoding = [
231 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
233 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
232 ]
234 ]
233
235
236+------------------------------------------------------------------------------
237+-- These tests check that JSONPath is tracked correctly
238+-----------------------------------------------------------------------------
239+
240+jsonPath :: [Assertion]
241+jsonPath = [
242+ -- issue #358
243+ assertEqual "Seq a"
244+ (Left "Error in $[2]: expected Int, encountered Boolean")
245+ (eitherDecode "[0,1,true]" :: Either String (Seq Int))
246+ ]
247+
234------------------------------------------------------------------------------
248------------------------------------------------------------------------------
235-- Regressions
249-- Regressions
236------------------------------------------------------------------------------
250------------------------------------------------------------------------------