allow building with aeson >= 2.0
In aeson 2.0, Text has been replaced by the Key type and HashMap by the KeyMap interface. Accomodating this required adding some CPP in order to still be able to compile with aeson < 2.0. The required changes were: * Prevent Key from being re-exported by Utilities.Aeson, as it clashes with git-annex's own Key type. * Fix up convertion from String/Text to Key (or Text in aeson 1.*) in a couple of places * Import Data.Aeson.KeyMap instead of Data.HashMap.Strict, as they are mostly API-compatible. insertWith needs to be replaced by unionWith, however, as KeyMap lacks the former function.
This commit is contained in:
parent
55f71b0ebd
commit
ca596e7c54
5 changed files with 51 additions and 15 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Types.MetaData (
|
||||
MetaData(..),
|
||||
|
@ -51,6 +52,9 @@ import Utility.QuickCheck
|
|||
import Utility.Aeson
|
||||
import Types.UUID
|
||||
|
||||
#if MIN_VERSION_aeson(2,0,0)
|
||||
import qualified Data.Aeson.Key as AK
|
||||
#endif
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as E
|
||||
import qualified Data.Set as S
|
||||
|
@ -67,7 +71,13 @@ newtype MetaData = MetaData (M.Map MetaField (S.Set MetaValue))
|
|||
instance ToJSON' MetaData where
|
||||
toJSON' (MetaData m) = object $ map go (M.toList m)
|
||||
where
|
||||
go (MetaField f, s) = (CI.original f, toJSON' s)
|
||||
go (MetaField f, s) =
|
||||
(
|
||||
#if MIN_VERSION_aeson(2,0,0)
|
||||
AK.fromText $
|
||||
#endif
|
||||
CI.original f
|
||||
, toJSON' s)
|
||||
|
||||
instance FromJSON MetaData where
|
||||
parseJSON (Object o) = do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue