on master help sign in
Track JSONPath in the FromJSON instance for Seq

Fixes #358

commit386585c88d64a262dd731a8a82d59e85f2d40396 authorArtyom <yom@artyom.me> dateSun 7 Feb 2016, 17:17 (11 years ago) parent74b2ed6
2 files changed+17−1
Data/Aeson/Types/Instances.hs+3−1 tests/UnitTests.hs+14
Data/Aeson/Types/Instances.hs+3−1
@@ -511,7 +511,9 @@ instance (ToJSON a) => ToJSON (Seq.Seq a) where
511511 {-# INLINE toEncoding #-}
512512
513513instance (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
515517 {-# INLINE parseJSON #-}
516518
517519instance (ToJSON a) => ToJSON (Vector a) where
tests/UnitTests.hs+14
@@ -14,6 +14,7 @@ import Data.Char (toUpper)
1414import Data.Maybe (fromMaybe)
1515import Data.Time (UTCTime)
1616import Data.Time.Format (parseTime)
17+import Data.Sequence (Seq)
1718import GHC.Generics (Generic)
1819import Test.Framework (Test, testGroup)
1920import Test.Framework.Providers.HUnit (testCase)
@@ -57,6 +58,7 @@ tests = testGroup "unit" [
5758 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
5859 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
5960 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
61+ , testGroup "JSONPath" $ fmap (testCase "-") jsonPath
6062 , testGroup "Issue #351" $ fmap (testCase "-") issue351
6163 ]
6264
@@ -231,6 +233,18 @@ jsonDecoding = [
231233 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
232234 ]
233235
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+
234248------------------------------------------------------------------------------
235249-- Regressions
236250------------------------------------------------------------------------------