aeson-extra 0.2.0.0 → 0.2.1.0
raw patch · 5 files changed
+37/−11 lines, 5 filesdep +taggeddep ~aesondep ~base
Dependencies added: tagged
Dependency ranges changed: aeson, base
Files
- CHANGELOG.md +4/−0
- aeson-extra.cabal +6/−4
- src/Data/Aeson/Compat.hs +1/−1
- src/Data/Aeson/Extra.hs +16/−5
- test/Tests.hs +10/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.2.1.0 (2015-10-05) GHC 7.6 Support++- No `Sym` or `SingObject` support+ # 0.2.0.0 (2015-09-29) No ListLike - Make `CollapsedList` use typeclasses in `base`
aeson-extra.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: aeson-extra-version: 0.2.0.0+version: 0.2.1.0 synopsis: Extra goodies for aeson description: The package motivation is twofold: .@@ -17,7 +17,7 @@ maintainer: Oleg Grenrus <oleg.grenrus@iki.fi> license: BSD3 license-file: LICENSE-tested-with: GHC==7.8.4, GHC==7.10.2+tested-with: GHC==7.6.3, GHC==7.8.4, GHC==7.10.2 build-type: Simple cabal-version: >= 1.10 @@ -34,7 +34,7 @@ src ghc-options: -Wall build-depends:- base >=4.7 && <4.9+ base >=4.6 && <4.9 , aeson >=0.8 && <0.11 , attoparsec >=0.12 && <0.14 , bytestring >=0.10 && <0.11@@ -42,6 +42,7 @@ , exceptions >=0.8 && <0.9 , hashable >=1.2 && <1.3 , scientific >=0.3 && <0.4+ , tagged >=0.7 && <0.9 , text >=1.2 && <1.3 , unordered-containers >=0.2 && <0.3 , vector >=0.10 && <0.12@@ -57,7 +58,7 @@ test ghc-options: -Wall build-depends:- base >=4.7 && <4.9+ base >=4.6 && <4.9 , aeson >=0.8 && <0.11 , attoparsec >=0.12 && <0.14 , bytestring >=0.10 && <0.11@@ -65,6 +66,7 @@ , exceptions >=0.8 && <0.9 , hashable >=1.2 && <1.3 , scientific >=0.3 && <0.4+ , tagged >=0.7 && <0.9 , text >=1.2 && <1.3 , unordered-containers >=0.2 && <0.3 , vector >=0.10 && <0.12
src/Data/Aeson/Compat.hs view
@@ -59,7 +59,7 @@ import Data.Text as T import Data.Typeable (Typeable) --- | Exception thrown by 'throwDecode' - family of functions.+-- | Exception thrown by 'decode' - family of functions in this module. newtype AesonException = AesonException String deriving (Show, Typeable)
src/Data/Aeson/Extra.hs view
@@ -25,12 +25,14 @@ FromJSONMap(..), ToJSONKey(..), ToJSONMap(..),+#if MIN_VERSION_base(4,7,0) -- * Symbol tag SymTag(..), -- * Singleton object SingObject(..), mkSingObject, getSingObject,+#endif -- * CollapsedList CollapsedList(..), getCollapsedList,@@ -52,11 +54,14 @@ import qualified Data.HashMap.Strict as H import Data.Hashable (Hashable) import qualified Data.Map as Map-import Data.Proxy import Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Read as T++#if MIN_VERSION_base(4,7,0)+import Data.Proxy import GHC.TypeLits+#endif -- | A wrapper type to parse arbitrary maps --@@ -118,16 +123,19 @@ instance (ToJSONMap m k v) => ToJSON (M m) where toJSON (M m) = Object (toJSONMap m) +#if MIN_VERSION_base(4,7,0) -- | Singleton string encoded and decoded as ifself. -- -- > λ> encode (SymTag :: SymTag "foobar") -- > "\"foobar\"" -- -- > decode "\"foobar\"" :: Maybe (SymTag "foobar")--- > Just Sym+-- > Just SymTag -- -- > decode "\"foobar\"" :: Maybe (SymTag "barfoo") -- > Nothing+--+-- > /Available with: base >=4.7/ data SymTag (s :: Symbol) = SymTag deriving (Eq, Ord, Show, Read, Enum, Bounded) @@ -150,6 +158,8 @@ -- -- > λ > encode (SingObject 42 :: SingObject "value" Int) -- > "{\"value\":42}"+--+-- > /Available with: base >=4.7/ newtype SingObject (s ::Symbol) a = SingObject a deriving (Eq, Ord, Show, Read, Functor, Foldable, Traversable) @@ -160,7 +170,7 @@ getSingObject _ (SingObject x) = x instance (KnownSymbol s, FromJSON a) => FromJSON (SingObject s a) where- parseJSON = withObject ("SingObject "<> show key) $ \obj -> + parseJSON = withObject ("SingObject "<> show key) $ \obj -> SingObject <$> obj .: T.pack key where key = symbolVal (Proxy :: Proxy s) @@ -171,6 +181,7 @@ #endif toJSON (SingObject x) = object [T.pack key .= x] where key = symbolVal (Proxy :: Proxy s)+#endif -- | Collapsed list, singleton is represented as the value itself in JSON encoding.@@ -218,7 +229,7 @@ -- | Parses possibly collapsed array value from the object's field. -- -- > λ > newtype V = V [Int] deriving (Show)--- > λ > instance FromJSON V where parseJSON = withObject "V" $ \obj -> V <$> collapsedList obj "value"+-- > λ > instance FromJSON V where parseJSON = withObject "V" $ \obj -> V <$> parseCollapsedList obj "value" -- > λ > decode "{}" :: Maybe V -- > Just (V []) -- > λ > decode "{\"value\": null}" :: Maybe V@@ -231,7 +242,7 @@ parseCollapsedList obj key = case H.lookup key obj of Nothing -> pure Control.Applicative.empty-#if MIN_VERSION_aeson(0,10,0) +#if MIN_VERSION_aeson(0,10,0) Just v -> modifyFailure addKeyName $ (getCollapsedList <$> parseJSON v) -- <?> Key key where addKeyName = (("failed to parse field " <> T.unpack key <> ": ") <>)
test/Tests.hs view
@@ -11,21 +11,26 @@ import Data.Aeson.Extra import qualified Data.HashMap.Lazy as H import Data.Map (Map)-import Data.Proxy import Data.Vector (Vector) import Test.QuickCheck.Instances () import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck +#if MIN_VERSION_base(4,7,0)+import Data.Proxy+#endif+ import Orphans () main :: IO () main = defaultMain $ testGroup "Tests" [ dotColonMark , mTests+#if MIN_VERSION_base(4,7,0) , symTests , singObjectTests+#endif , collapsedListTests ] @@ -47,6 +52,8 @@ ] where result = M $ H.fromList [(1,1),(2,2)] +#if MIN_VERSION_base(4,7,0)+ ------------------------------------------------------------------------------ -- SymTag ------------------------------------------------------------------------------@@ -78,6 +85,8 @@ p = Proxy in prop ]++#endif ------------------------------------------------------------------------------ -- parseCollapsedList