@@ -46,7 +46,12 @@ import Data.Aeson.Text
46
46
import Data.Aeson.Encode
47
47
#endif
48
48
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
50
55
import qualified Data.Text as T
51
56
import qualified Data.Text.Lazy as TL
52
57
import qualified Data.Text.Lazy.Builder as TLB
@@ -418,8 +423,13 @@ data Bug = Bug
418
423
, bugUrl :: T. Text
419
424
, bugVersion :: [T. Text ]
420
425
, 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 ]
423
433
} deriving (Eq , Show )
424
434
425
435
instance FromJSON Bug where
@@ -464,9 +474,14 @@ instance FromJSON Bug where
464
474
<*> v .:? " external_bugs"
465
475
parseJSON _ = mzero
466
476
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
470
485
where
471
486
stringifyCustomFields :: Value -> T. Text
472
487
stringifyCustomFields (String t) = t
@@ -477,7 +492,10 @@ customFields = H.map stringifyCustomFields
477
492
. toJSON
478
493
$ v
479
494
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
481
499
482
500
newtype BugList = BugList [Bug ]
483
501
deriving (Eq , Show )
@@ -544,8 +562,8 @@ instance FromJSON AttachmentList where
544
562
attachmentsVal <- v .: " attachments"
545
563
bugsVal <- v .: " bugs"
546
564
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
549
567
_ -> mzero
550
568
parseJSON _ = mzero
551
569
@@ -581,7 +599,7 @@ instance FromJSON CommentList where
581
599
parseJSON (Object v) = do
582
600
bugsVal <- v .: " bugs"
583
601
case bugsVal of
584
- Object (H . toList -> [(_, cs)]) ->
602
+ Object (M . toList -> [(_, cs)]) ->
585
603
do comments <- withObject " comments" (.: " comments" ) cs
586
604
withArray " comment list" (\ a -> CommentList <$> parseJSON (addCount a)) comments
587
605
_ -> mzero
@@ -594,7 +612,7 @@ addCount :: V.Vector Value -> Value
594
612
addCount vs = Array $ V. zipWith addCount' (V. enumFromN 0 $ V. length vs) vs
595
613
where
596
614
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
598
616
addCount' _ v = v
599
617
600
618
-- | History information for a bug.
0 commit comments