on master help sign in
Merge pull request #360 from neongreen/master
7dcbec5Adam Bergmark
Data/Aeson/Types/Instances.hs+2−2
@@ -166,8 +166,8 @@ instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
166
166
167instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
167instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
168 parseJSON (Object (H.toList -> [(key, value)]))
168 parseJSON (Object (H.toList -> [(key, value)]))
169− | key == left = Left <$> parseJSON value
169+ | key == left = Left <$> parseJSON value <?> Key left
170− | key == right = Right <$> parseJSON value
170+ | key == right = Right <$> parseJSON value <?> Key right
171 parseJSON _ = fail $
171 parseJSON _ = fail $
172 "expected an object with a single property " ++
172 "expected an object with a single property " ++
173 "where the property key should be either " ++
173 "where the property key should be either " ++
tests/UnitTests.hs+6−1
@@ -239,8 +239,13 @@ jsonDecoding = [
239
239
240jsonPath :: [Assertion]
240jsonPath :: [Assertion]
241jsonPath = [
241jsonPath = [
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) ()))
242 -- issue #358
247 -- issue #358
243− assertEqual "Seq a"
248+ , assertEqual "Seq a"
244 (Left "Error in $[2]: expected Int, encountered Boolean")
249 (Left "Error in $[2]: expected Int, encountered Boolean")
245 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
250 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
246 ]
251 ]