aeson 0.11.1.0 → 0.11.1.1
raw patch · 4 files changed
+34/−5 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Aeson: parseJSON :: FromJSON a => Value -> Parser a
+ Data.Aeson: parseJSON :: (FromJSON a, Generic a, GFromJSON (Rep a)) => Value -> Parser a
- Data.Aeson: toJSON :: ToJSON a => a -> Value
+ Data.Aeson: toJSON :: (ToJSON a, Generic a, GToJSON (Rep a)) => a -> Value
- Data.Aeson.Types: parseJSON :: FromJSON a => Value -> Parser a
+ Data.Aeson.Types: parseJSON :: (FromJSON a, Generic a, GFromJSON (Rep a)) => Value -> Parser a
- Data.Aeson.Types: toJSON :: ToJSON a => a -> Value
+ Data.Aeson.Types: toJSON :: (ToJSON a, Generic a, GToJSON (Rep a)) => a -> Value
Files
- Data/Aeson/Types/Internal.hs +12/−2
- aeson.cabal +2/−1
- changelog.md +5/−1
- tests/UnitTests.hs +15/−1
Data/Aeson/Types/Internal.hs view
@@ -90,6 +90,10 @@ import Data.Traversable (Traversable(..)) #endif +#if !MIN_VERSION_unordered_containers(0,2,6)+import Data.List (foldl', sort)+#endif+ -- | Elements of a JSON path used to describe the location of an -- error. data JSONPathElement = Key Text@@ -391,8 +395,14 @@ {-# INLINE fromString #-} hashValue :: Int -> Value -> Int-hashValue s (Object o) = H.foldl' hashWithSalt- (s `hashWithSalt` (0::Int)) o+#if MIN_VERSION_unordered_containers(0,2,6)+hashValue s (Object o) = s `hashWithSalt` (0::Int) `hashWithSalt` o+#else+hashValue s (Object o) = foldl' hashWithSalt+ (s `hashWithSalt` (0::Int)) assocHashesSorted+ where+ assocHashesSorted = sort [hash k `hashWithSalt` v | (k, v) <- H.toList o]+#endif hashValue s (Array a) = V.foldl' hashWithSalt (s `hashWithSalt` (1::Int)) a hashValue s (String str) = s `hashWithSalt` (2::Int) `hashWithSalt` str
aeson.cabal view
@@ -1,5 +1,5 @@ name: aeson-version: 0.11.1.0+version: 0.11.1.1 license: BSD3 license-file: LICENSE category: Text, Web, JSON@@ -158,6 +158,7 @@ bytestring, containers, ghc-prim >= 0.2,+ hashable >= 1.1.2.0, tagged, template-haskell, test-framework,
changelog.md view
@@ -1,6 +1,10 @@ For the latest version of this document, please see [https://github.com/bos/aeson/blob/master/changelog.md](https://github.com/bos/aeson/blob/master/changelog.md). -## 0.11.1.0+#### 0.11.1.1++* Fixes a bug where the hashes of equal values could differ.++### 0.11.1.0 The only changes are added instances.
tests/UnitTests.hs view
@@ -6,12 +6,13 @@ import Control.Applicative (Const(..)) import Control.Monad (forM)-import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding, FromJSON(..), withObject, (.:), (.:?), (.:!))+import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding, object, FromJSON(..), withObject, (.=), (.:), (.:?), (.:!)) import Data.Aeson.Encode (encodeToTextBuilder) import Data.Aeson.Internal (JSONPathElement(..), formatError) import Data.Aeson.TH (deriveJSON) import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields) import Data.Char (toUpper)+import Data.Hashable (hash) import Data.List.NonEmpty (NonEmpty(..)) import Data.Maybe (fromMaybe) import Data.Proxy (Proxy(..))@@ -63,6 +64,7 @@ , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding , testGroup "JSONPath" $ fmap (testCase "-") jsonPath+ , testGroup "Hashable laws" $ fmap (testCase "-") hashableLaws , testGroup "Issue #351" $ fmap (testCase "-") issue351 ] @@ -260,6 +262,18 @@ (Left "Error in $[2]: expected Int, encountered Boolean") (eitherDecode "[0,1,true]" :: Either String (Seq Int)) ]++------------------------------------------------------------------------------+-- Check that the hashes of two equal Value are the same+------------------------------------------------------------------------------++hashableLaws :: [Assertion]+hashableLaws = [+ assertEqual "Hashable Object" (hash a) (hash b)+ ]+ where+ a = object ["223" .= False, "807882556" .= True]+ b = object ["807882556" .= True, "223" .= False] ------------------------------------------------------------------------------ -- Regressions