aeson-bson 0.2.0 → 0.3.0
raw patch · 4 files changed
+72/−82 lines, 4 filesdep −HUnitdep −test-frameworkdep −test-framework-hunitdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies removed: HUnit, test-framework, test-framework-hunit
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.AesonBson: aesonifyValue :: Value -> Value
- Data.AesonBson: bsonifyValue :: Value -> Value
- Data.AesonBson: instance ToJSON Document
- Data.AesonBson: instance ToJSON Value
- Data.AesonBson: toAeson :: Document -> Object
- Data.AesonBson: toBson :: Object -> Document
+ Data.Aeson.Bson: aesonifyValue :: Value -> Value
+ Data.Aeson.Bson: bsonifyValue :: Value -> Value
+ Data.Aeson.Bson: instance ToJSON Document
+ Data.Aeson.Bson: instance ToJSON Value
+ Data.Aeson.Bson: toAeson :: Document -> Object
+ Data.Aeson.Bson: toBson :: Object -> Document
Files
- README.md +5/−3
- aeson-bson.cabal +3/−15
- src/Data/Aeson/Bson.hs +64/−0
- src/Data/AesonBson.hs +0/−64
README.md view
@@ -1,5 +1,7 @@-This package is a spin-off of the original package "AesonBson": -http://hackage.haskell.org/package/AesonBson-0.2.0+Fork from the original work: http://hackage.haskell.org/package/AesonBson -All the credits to the original authors for their job.+This package takes api-breaking decisions like:++* Different library namespace (Data.Aeson.Bson)+* Different function names for exposed functions (toAeson and toBson)
aeson-bson.cabal view
@@ -1,5 +1,5 @@ Name: aeson-bson-Version: 0.2.0+Version: 0.3.0 License: OtherLicense License-File: LICENSE Maintainer: Niklas Hambuechen <mail@nh2.me>@@ -10,7 +10,7 @@ Description: This package lets you convert between Aeson's JSON and Bson objects. Category: Data Copyright: CC0-Cabal-Version: >= 1.8+Cabal-Version: >= 1.6 Homepage: Tested-With: GHC == 7.6.2 @@ -40,17 +40,5 @@ unordered-containers >= 0.1.3.0, vector -any Exposed-Modules:- Data.AesonBson+ Data.Aeson.Bson Ghc-Options: -Wall -fno-warn-orphans--Test-Suite test-all-- type: exitcode-stdio-1.0- - main-is: test/Main.hs- - build-depends:- base < 5,- HUnit >= 1.2.5.1,- test-framework >= 0.8,- test-framework-hunit >= 0.3.0
+ src/Data/Aeson/Bson.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE FlexibleInstances #-}++module Data.Aeson.Bson (+ toAeson, aesonifyValue,+ toBson, bsonifyValue+) where++import Data.Bson as BSON+import Data.Aeson.Types as AESON+import Data.Attoparsec.Number as Atto+import Data.Text as T hiding (map)+import Data.HashMap.Strict as Map (fromList, toList)+import Data.Vector as Vector (toList)+import Numeric++instance ToJSON BSON.Value where+ toJSON = aesonifyValue++instance ToJSON Document where+ toJSON = Object . toAeson++bsonifyValue :: AESON.Value -> BSON.Value+bsonifyValue (Object obj) = Doc $ toBson obj+bsonifyValue (AESON.Array array) = BSON.Array . map bsonifyValue . Vector.toList $ array+bsonifyValue (AESON.String str) = BSON.String str+bsonifyValue (Number n) = case n of { I int -> Int64 $ fromIntegral int+ ; D float -> Float float }+bsonifyValue (AESON.Bool b) = BSON.Bool b+bsonifyValue (AESON.Null) = BSON.Null++aesonifyValue :: BSON.Value -> AESON.Value+aesonifyValue (Float f) = toJSON f+aesonifyValue (BSON.String s) = toJSON s+aesonifyValue (Doc doc) = toJSON doc+aesonifyValue (BSON.Array list) = toJSON list+aesonifyValue (Bin (Binary binary)) = toJSON binary+aesonifyValue (Fun (Function function)) = toJSON function+aesonifyValue (Uuid (UUID uuid)) = toJSON uuid+aesonifyValue (Md5 (MD5 md5)) = toJSON md5+aesonifyValue (UserDef (UserDefined userdef)) = toJSON userdef+aesonifyValue (ObjId (Oid w32 w64)) = toJSON $ showHex w32 (showHex w64 "")+aesonifyValue (BSON.Bool bool) = toJSON bool+aesonifyValue (UTC utc) = toJSON utc+aesonifyValue (BSON.Null) = AESON.Null+aesonifyValue (RegEx (Regex pattern mods)) = toJSON $+ '/' : T.unpack pattern +++ '/' : T.unpack mods+aesonifyValue (JavaScr (Javascript env code)) = toJSON . Map.fromList $+ [ (T.pack "environment", toJSON env)+ , (T.pack "code", toJSON code)]+aesonifyValue (Sym (Symbol sym)) = toJSON sym+aesonifyValue (Int32 int32) = toJSON int32+aesonifyValue (Int64 int64) = toJSON int64+aesonifyValue (Stamp (MongoStamp int64)) = toJSON int64+aesonifyValue (MinMax mm) = case mm of { MinKey -> toJSON (-1 :: Int)+ ; MaxKey -> toJSON (1 :: Int)}+++toBson :: AESON.Object -> BSON.Document+toBson = map (\(t, v) -> (t := bsonifyValue v)) . Map.toList++toAeson :: BSON.Document -> AESON.Object+toAeson = Map.fromList . map (\(l := v) -> (l, aesonifyValue v))
− src/Data/AesonBson.hs
@@ -1,64 +0,0 @@-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE FlexibleInstances #-}--module Data.AesonBson (- toAeson, aesonifyValue,- toBson, bsonifyValue-) where--import Data.Bson as BSON-import Data.Aeson.Types as AESON-import Data.Attoparsec.Number as Atto-import Data.Text as T hiding (map)-import Data.HashMap.Strict as Map (fromList, toList)-import Data.Vector as Vector (toList)-import Numeric--instance ToJSON BSON.Value where- toJSON = aesonifyValue--instance ToJSON Document where- toJSON = Object . toAeson--bsonifyValue :: AESON.Value -> BSON.Value-bsonifyValue (Object obj) = Doc $ toBson obj-bsonifyValue (AESON.Array array) = BSON.Array . map bsonifyValue . Vector.toList $ array-bsonifyValue (AESON.String str) = BSON.String str-bsonifyValue (Number n) = case n of { I int -> Int64 $ fromIntegral int- ; D float -> Float float }-bsonifyValue (AESON.Bool b) = BSON.Bool b-bsonifyValue (AESON.Null) = BSON.Null--aesonifyValue :: BSON.Value -> AESON.Value-aesonifyValue (Float f) = toJSON f-aesonifyValue (BSON.String s) = toJSON s-aesonifyValue (Doc doc) = toJSON doc-aesonifyValue (BSON.Array list) = toJSON list-aesonifyValue (Bin (Binary binary)) = toJSON binary-aesonifyValue (Fun (Function function)) = toJSON function-aesonifyValue (Uuid (UUID uuid)) = toJSON uuid-aesonifyValue (Md5 (MD5 md5)) = toJSON md5-aesonifyValue (UserDef (UserDefined userdef)) = toJSON userdef-aesonifyValue (ObjId (Oid w32 w64)) = toJSON $ showHex w32 (showHex w64 "")-aesonifyValue (BSON.Bool bool) = toJSON bool-aesonifyValue (UTC utc) = toJSON utc-aesonifyValue (BSON.Null) = AESON.Null-aesonifyValue (RegEx (Regex pattern mods)) = toJSON $- '/' : T.unpack pattern ++- '/' : T.unpack mods-aesonifyValue (JavaScr (Javascript env code)) = toJSON . Map.fromList $- [ (T.pack "environment", toJSON env)- , (T.pack "code", toJSON code)]-aesonifyValue (Sym (Symbol sym)) = toJSON sym-aesonifyValue (Int32 int32) = toJSON int32-aesonifyValue (Int64 int64) = toJSON int64-aesonifyValue (Stamp (MongoStamp int64)) = toJSON int64-aesonifyValue (MinMax mm) = case mm of { MinKey -> toJSON (-1 :: Int)- ; MaxKey -> toJSON (1 :: Int)}---toBson :: AESON.Object -> BSON.Document-toBson = map (\(t, v) -> (t := bsonifyValue v)) . Map.toList--toAeson :: BSON.Document -> AESON.Object-toAeson = Map.fromList . map (\(l := v) -> (l, aesonifyValue v))