Skip to content

Commit 582c33b

Browse files
committed
support building with aeson-2.0 (haskell/aeson#881)
1 parent 0de7fa2 commit 582c33b

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

bugzilla-redhat.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ library
3737
Web.Bugzilla.RedHat.Internal.Search,
3838
Web.Bugzilla.RedHat.Internal.Types
3939
build-depends: base >=4.6 && <5,
40-
aeson >=0.7 && <1.6,
40+
aeson >=0.7 && <3,
4141
blaze-builder >=0.3 && <0.5,
4242
bytestring >=0.10 && <0.11,
4343
connection >=0.2 && <0.4,

src/Web/Bugzilla/RedHat/Internal/Types.hs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ import Data.Aeson.Text
4646
import Data.Aeson.Encode
4747
#endif
4848
import Data.Aeson.Types
49-
import qualified Data.HashMap.Strict as H
49+
#if MIN_VERSION_aeson(2,0,0)
50+
import Data.Aeson.Key
51+
import qualified Data.Aeson.KeyMap as M
52+
#else
53+
import qualified Data.HashMap.Strict as M
54+
#endif
5055
import qualified Data.Text as T
5156
import qualified Data.Text.Lazy as TL
5257
import qualified Data.Text.Lazy.Builder as TLB
@@ -418,8 +423,13 @@ data Bug = Bug
418423
, bugUrl :: T.Text
419424
, bugVersion :: [T.Text]
420425
, bugWhiteboard :: T.Text
421-
, bugCustomFields :: H.HashMap T.Text T.Text
422-
, bugExternalBugs :: Maybe [ExternalBug]
426+
, bugCustomFields ::
427+
#if MIN_VERSION_aeson(2,0,0)
428+
M.KeyMap T.Text
429+
#else
430+
M.HashMap T.Text T.Text
431+
#endif
432+
, bugExternalBugs :: Maybe [ExternalBug]
423433
} deriving (Eq, Show)
424434

425435
instance FromJSON Bug where
@@ -464,9 +474,14 @@ instance FromJSON Bug where
464474
<*> v .:? "external_bugs"
465475
parseJSON _ = mzero
466476

467-
customFields :: Object -> H.HashMap T.Text T.Text
468-
customFields = H.map stringifyCustomFields
469-
. H.filterWithKey filterCustomFields
477+
customFields :: Object ->
478+
#if MIN_VERSION_aeson(2,0,0)
479+
M.KeyMap T.Text
480+
#else
481+
M.HashMap T.Text T.Text
482+
#endif
483+
customFields = M.map stringifyCustomFields
484+
. M.filterWithKey filterCustomFields
470485
where
471486
stringifyCustomFields :: Value -> T.Text
472487
stringifyCustomFields (String t) = t
@@ -477,7 +492,10 @@ customFields = H.map stringifyCustomFields
477492
. toJSON
478493
$ v
479494

480-
filterCustomFields k _ = "cf_" `T.isPrefixOf` k
495+
filterCustomFields k _ = "cf_" `T.isPrefixOf` toText k
496+
#if !MIN_VERSION_aeson(2,0,0)
497+
where toText = id
498+
#endif
481499

482500
newtype BugList = BugList [Bug]
483501
deriving (Eq, Show)
@@ -544,8 +562,8 @@ instance FromJSON AttachmentList where
544562
attachmentsVal <- v .: "attachments"
545563
bugsVal <- v .: "bugs"
546564
case (attachmentsVal, bugsVal) of
547-
(Object (H.toList -> [(_, as)]), _) -> AttachmentList . (:[]) <$> parseJSON as
548-
(_, Object (H.toList -> [(_, as)])) -> AttachmentList <$> parseJSON as
565+
(Object (M.toList -> [(_, as)]), _) -> AttachmentList . (:[]) <$> parseJSON as
566+
(_, Object (M.toList -> [(_, as)])) -> AttachmentList <$> parseJSON as
549567
_ -> mzero
550568
parseJSON _ = mzero
551569

@@ -581,7 +599,7 @@ instance FromJSON CommentList where
581599
parseJSON (Object v) = do
582600
bugsVal <- v .: "bugs"
583601
case bugsVal of
584-
Object (H.toList -> [(_, cs)]) ->
602+
Object (M.toList -> [(_, cs)]) ->
585603
do comments <- withObject "comments" (.: "comments") cs
586604
withArray "comment list" (\a -> CommentList <$> parseJSON (addCount a)) comments
587605
_ -> mzero
@@ -594,7 +612,7 @@ addCount :: V.Vector Value -> Value
594612
addCount vs = Array $ V.zipWith addCount' (V.enumFromN 0 $ V.length vs) vs
595613
where
596614
addCount' :: Int -> Value -> Value
597-
addCount' c (Object v) = Object $ H.insert "count" (Number $ fromIntegral c) v
615+
addCount' c (Object v) = Object $ M.insert "count" (Number $ fromIntegral c) v
598616
addCount' _ v = v
599617

600618
-- | History information for a bug.

0 commit comments

Comments
 (0)