packages feed

AesonBson 0.4.0 → 0.4.1

raw patch · 3 files changed

+28/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

AesonBson.cabal view
@@ -1,5 +1,5 @@ name:          AesonBson-version:       0.4.0+version:       0.4.1 license:       OtherLicense license-file:  LICENSE copyright:     CC0@@ -9,7 +9,7 @@ build-type:    Simple stability:     experimental tested-With:   GHC==7.4.2-cabal-version: >= 1.8+cabal-version: >= 1.10 homepage:      https://github.com/nh2/AesonBson bug-Reports:   https://github.com/nh2/AesonBson/issues synopsis:      Mapping between Aeson's JSON and Bson objects.@@ -38,6 +38,7 @@     unordered-containers >= 0.1.3.0,     vector >= 0.7.1   hs-source-dirs: .+  default-language: Haskell2010   ghc-options: -Wall  test-Suite tests@@ -56,4 +57,5 @@     scientific >= 0.2,     QuickCheck >= 2.6,     text >= 0.11.3.1+  default-language: Haskell2010   ghc-options: -Wall
CHANGELOG view
@@ -1,3 +1,8 @@+# 0.4.1++* Compatibility with current `aeson` 2.0+  (https://github.com/nh2/aesonbson/pull/12)+ # 0.4.0  * Compatibility with current `aeson`
Data/AesonBson.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}  -- | Convert JSON to BSON and the other way around.@@ -23,11 +24,26 @@ import           Data.Bson as BSON import           Data.Aeson.Types as AESON import           Data.Int-import qualified Data.HashMap.Strict as HashMap (fromList, toList) import qualified Data.Scientific as S+import qualified Data.Text as Text import qualified Data.Text.Encoding as T import qualified Data.Vector as Vector (fromList, toList) +# if MIN_VERSION_aeson(2, 0, 0)+import qualified Data.Aeson.Key as Key+import qualified Data.Aeson.KeyMap as HashMap (fromList, toList)+textToKey :: Text.Text -> AESON.Key+textToKey = Key.fromText+keyToText :: AESON.Key -> Text.Text+keyToText = Key.toText+# else+import qualified Data.HashMap.Strict as HashMap (fromList, toList)+textToKey :: Text.Text -> Text.Text+textToKey = id+keyToText :: Text.Text -> Text.Text+keyToText = id+# endif+ -- | Converts an AESON object to a BSON document. Will yeld an error for JSON numbers that are too big. bsonifyError :: AESON.Object -> BSON.Document bsonifyError = bsonify errorRange@@ -38,11 +54,11 @@  -- | Converts an AESON object to a BSON document. The user can provide a function to deal with JSON numbers that are too big. bsonify :: (S.Scientific -> BSON.Value) -> AESON.Object -> BSON.Document-bsonify f o = map (\(t, v) -> t := bsonifyValue f v) $ HashMap.toList o+bsonify f o = map (\(t, v) -> keyToText t := bsonifyValue f v) $ HashMap.toList o  -- | Converts a BSON document to an AESON object. aesonify :: BSON.Document -> AESON.Object-aesonify = HashMap.fromList . map (\(l := v) -> (l, aesonifyValue v))+aesonify = HashMap.fromList . map (\(l := v) -> (textToKey l, aesonifyValue v))   -- | Helpers