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

Fixes #356

commit8d3dd5b1cbefe9b20de65e03da7a7f77955f17ca authorArtyom <yom@artyom.me> dateMon 8 Feb 2016, 03:50 (11 years ago) parentc6ee242
2 files changed+8−3
Data/Aeson/Types/Instances.hs+2−2 tests/UnitTests.hs+6−1
Data/Aeson/Types/Instances.hs+2−2
@@ -166,8 +166,8 @@ instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
166166
167167instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
168168 parseJSON (Object (H.toList -> [(key, value)]))
169− | key == left = Left <$> parseJSON value
170− | key == right = Right <$> parseJSON value
169+ | key == left = Left <$> parseJSON value <?> Key left
170+ | key == right = Right <$> parseJSON value <?> Key right
171171 parseJSON _ = fail $
172172 "expected an object with a single property " ++
173173 "where the property key should be either " ++
tests/UnitTests.hs+6−1
@@ -239,8 +239,13 @@ jsonDecoding = [
239239
240240jsonPath :: [Assertion]
241241jsonPath = [
242+ -- issue #356
243+ assertEqual "Either"
244+ (Left "Error in $[1].Left[1]: expected Bool, encountered Number")
245+ (eitherDecode "[1,{\"Left\":[2,3]}]"
246+ :: Either String (Int, Either (Int, Bool) ()))
242247 -- issue #358
243− assertEqual "Seq a"
248+ , assertEqual "Seq a"
244249 (Left "Error in $[2]: expected Int, encountered Boolean")
245250 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
246251 ]