From c7bae27f009ccaae4d365dc2471c0725de2f5793 Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Thu, 24 Mar 2022 10:58:13 +0100 Subject: Support aeson 2.0 As per the aeson 2.0.0.0 changelog[1], starting with that version the map type used by Object is now abstract, as is the key type of that map. Related: https://github.com/haskell/aeson/pull/866 Related: https://github.com/haskell/aeson/pull/868 [1]: https://hackage.haskell.org/package/aeson-2.0.0.0/changelog --- Gpg/Wot.hs | 13 ++++++++++++- debug-me.cabal | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Gpg/Wot.hs b/Gpg/Wot.hs index 2a6d541..d916ebc 100644 --- a/Gpg/Wot.hs +++ b/Gpg/Wot.hs @@ -3,6 +3,7 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} -- | Gpg web of trust checking, using wotsap's JSON output @@ -15,8 +16,13 @@ import JSON import Network.HTTP.Client import Network.HTTP.Client.TLS import Data.List -import qualified Data.HashMap.Strict as M import qualified Data.Text as T +#if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as AM +import qualified Data.Aeson.Key as AK +#else +import qualified Data.HashMap.Strict as M +#endif data WotStats = WotStats { key :: Node @@ -43,9 +49,14 @@ data Node = Node -- | wotsap's json has some upper-case fields; lowercase field for parsing jsonLower :: Value -> Value +#if MIN_VERSION_aeson(2, 0, 0) +jsonLower (Object o) = Object . AM.mapKeyVal lowerKey id $ o + where lowerKey = AK.fromText . T.toLower . AK.toText +#else jsonLower (Object o) = Object . M.fromList . map lowerPair . M.toList $ o where lowerPair (k, v) = (T.toLower k, v) +#endif jsonLower x = x instance FromJSON WotStats where diff --git a/debug-me.cabal b/debug-me.cabal index d859cbb..db7cc63 100644 --- a/debug-me.cabal +++ b/debug-me.cabal @@ -64,7 +64,7 @@ Executable debug-me , stm-chans (>= 3.0) , posix-pty (>= 0.2.1) , terminal-size (>= 0.3) - , aeson (>= 0.11 && < 1.5) + , aeson (>= 0.11 && < 2.1) , sandi (>= 0.4) , text (>= 1.2.2) , optparse-applicative (>= 0.12) -- cgit v1.2.3