aeson-extra 0.5 → 0.5.1
raw patch · 5 files changed
+57/−20 lines, 5 filesdep ~aesondep ~basedep ~hashablePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, base, hashable, template-haskell, text
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- aeson-extra.cabal +4/−4
- src/Data/Aeson/Extra/CollapsedList.hs +16/−4
- src/Data/Aeson/Extra/Recursive.hs +12/−0
- src/Data/Aeson/Extra/SingObject.hs +21/−12
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.5.1 (2021-09-10)++- Support `aeson-2.0.0.0`+ # 0.5 (2021-03-22) - Trim lower bounds
aeson-extra.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: aeson-extra-version: 0.5+version: 0.5.1 synopsis: Extra goodies for aeson description: Package provides extra functionality on top of @aeson@ and @aeson-compat@@@ -36,11 +36,11 @@ hs-source-dirs: src ghc-options: -Wall build-depends:- aeson >=1.5.4.1 && <1.6- , attoparsec >=0.11.3.4 && <0.14+ aeson >=1.5.4.1 && <1.6 || >=2.0 && <2.1+ , attoparsec >=0.11.3.4 && <0.15 , attoparsec-iso8601 >=1.0 && <1.1 , base >=4.7 && <4.16- , base-compat-batteries >=0.11.2 && <0.12+ , base-compat-batteries >=0.11.2 && <0.13 , bytestring >=0.10 && <0.12 , containers >=0.5 && <0.7 , deepseq >=1.3 && <1.5
src/Data/Aeson/Extra/CollapsedList.hs view
@@ -30,10 +30,17 @@ #endif import qualified Data.Foldable as Foldable-import qualified Data.HashMap.Strict as HM import qualified Data.Text as T +#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.Key as Key+import qualified Data.Aeson.KeyMap as KM+#else+import qualified Data.HashMap.Strict as KM+#endif ++ -- | Collapsed list, singleton is represented as the value itself in JSON encoding. -- -- > λ > decode "null" :: Maybe (CollapsedList [Int] Int)@@ -102,9 +109,14 @@ -- > λ > decode "{\"value\": [1, 2, 3, 4]}" :: Maybe V -- > Just (V [1,2,3,4]) parseCollapsedList :: (FromJSON a, FromJSON1 f, Alternative f) => Object -> Text -> Parser (f a)-parseCollapsedList obj key =- case HM.lookup key obj of+parseCollapsedList obj key' =+ case KM.lookup key obj of Nothing -> pure Control.Applicative.empty Just v -> modifyFailure addKeyName $ (getCollapsedList <$> parseJSON v) -- <?> Key key where- addKeyName = (mappend ("failed to parse field " `mappend` T.unpack key `mappend`": "))+#if MIN_VERSION_aeson(2,0,0)+ key = Key.fromText key'+#else+ key = key'+#endif+ addKeyName = (mappend ("failed to parse field " `mappend` T.unpack key' `mappend`": "))
src/Data/Aeson/Extra/Recursive.hs view
@@ -45,6 +45,10 @@ import qualified Data.Functor.Foldable as F #endif +#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KM+#endif+ -- | A JSON \"object\" (key\/value map). -- -- /Since: aeson-extra-0.3.1.0/@@ -70,7 +74,11 @@ type instance Base Value = ValueF instance Recursive Value where+#if MIN_VERSION_aeson(2,0,0)+ project (Object o) = ObjectF (KM.toHashMapText o)+#else project (Object o) = ObjectF o+#endif project (Array a) = ArrayF a project (String s) = StringF s project (Number n) = NumberF n@@ -78,7 +86,11 @@ project Null = NullF instance Corecursive Value where+#if MIN_VERSION_aeson(2,0,0)+ embed (ObjectF o) = Object (KM.fromHashMapText o)+#else embed (ObjectF o) = Object o+#endif embed (ArrayF a) = Array a embed (StringF s) = String s embed (NumberF n) = Number n
src/Data/Aeson/Extra/SingObject.hs view
@@ -22,17 +22,26 @@ import Prelude () import Prelude.Compat -import Control.DeepSeq (NFData (..))+import Control.DeepSeq (NFData (..)) import Data.Aeson-import Data.Aeson.Encoding (pair)-import Data.Aeson.Internal (JSONPathElement (Key))-import Data.Proxy (Proxy (..))-import Data.Typeable (Typeable)-import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)+import Data.Aeson.Encoding (pair)+import Data.Aeson.Internal (JSONPathElement (Key))+import Data.Proxy (Proxy (..))+import Data.String (fromString)+import Data.Typeable (Typeable)+import GHC.TypeLits (KnownSymbol, Symbol, symbolVal) -import qualified Data.HashMap.Strict as HM-import qualified Data.Text as T+import qualified Data.Text as T +#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.Key as Key+import qualified Data.Aeson.KeyMap as KM+#else+import qualified Data.HashMap.Strict as KM+#endif+++ -- | Singleton value object -- -- > λ > decode "{\"value\": 42 }" :: Maybe (SingObject "value" Int)@@ -53,21 +62,21 @@ instance KnownSymbol s => FromJSON1 (SingObject s) where liftParseJSON p _ = withObject ("SingObject "<> show key) $ \obj ->- case HM.lookup key obj of+ case KM.lookup key obj of Nothing -> fail $ "key " ++ show key ++ " not present" Just v -> SingObject <$> p v <?> Key key where- key = T.pack $ symbolVal (Proxy :: Proxy s)+ key = fromString $ symbolVal (Proxy :: Proxy s) instance KnownSymbol s => ToJSON1 (SingObject s) where liftToJSON to _ (SingObject x) = object [ key .= to x] where- key = T.pack $ symbolVal (Proxy :: Proxy s)+ key = fromString $ symbolVal (Proxy :: Proxy s) liftToEncoding to _ (SingObject x) = pairs $ pair key $ to x where- key = T.pack $ symbolVal (Proxy :: Proxy s)+ key = fromString $ symbolVal (Proxy :: Proxy s) instance (KnownSymbol s, FromJSON a) => FromJSON (SingObject s a) where parseJSON = parseJSON1