import qualified Data.Vector as V
import qualified Data.ByteString.Lazy as L
#if MIN_VERSION_aeson(2,0,0)
-import qualified Data.Aeson.Key as AK
import qualified Data.Aeson.KeyMap as HM
#else
import qualified Data.HashMap.Strict as HM
j = case v of
AesonObject ao -> Object ao
JSONChunk l -> object $ map mkPair l
- mkPair (s, d) =
- (
-#if MIN_VERSION_aeson(2,0,0)
- AK.fromText $
-#endif
- packString s
- , toJSON' d)
+ mkPair (s, d) = (textKey (packString s), toJSON' d)
add _ Nothing = Nothing
complete :: JSONChunk v -> JSONBuilder
instance ToJSON' a => ToJSON' (ObjectMap a) where
toJSON' (ObjectMap m) = object $ map go $ M.toList m
where
- go (k, v) =
- (
-#if MIN_VERSION_aeson(2,0,0)
- AK.fromText $
-#endif
- packString k
- , toJSON' v)
+ go (k, v) = (textKey (packString k), toJSON' v)
-- An item that a git-annex command acts on, and displays a JSON object about.
data JSONActionItem a = JSONActionItem
- Licensed under the GNU AGPL version 3 or higher.
-}
-{-# LANGUAGE OverloadedStrings, CPP #-}
+{-# LANGUAGE OverloadedStrings #-}
module Remote (
Remote,
import Data.Ord
import Data.String
-#if MIN_VERSION_aeson(2,0,0)
-import qualified Data.Aeson.Key as AK
-#endif
import qualified Data.Map as M
import qualified Data.Vector as V
, Just ("here", toJSON' $ hereu == u)
, case (optfield, optval) of
(Just field, Just val) -> Just
- (
-#if MIN_VERSION_aeson(2,0,0)
- AK.fromText $
-#endif
- packString field
- , toJSON' val)
+ (textKey (packString field), toJSON' val)
_ -> Nothing
]
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE CPP #-}
module Types.MetaData (
MetaData(..),
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
instance ToJSON' MetaData where
toJSON' (MetaData m) = object $ map go (M.toList m)
where
- go (MetaField f, s) =
- (
-#if MIN_VERSION_aeson(2,0,0)
- AK.fromText $
-#endif
- CI.original f
- , toJSON' s)
+ go (MetaField f, s) = (textKey (CI.original f), toJSON' s)
instance FromJSON MetaData where
parseJSON (Object o) = do
encode,
packString,
packByteString,
+ textKey,
) where
import Data.Aeson as X hiding (ToJSON, toJSON, encode, Key)
import Data.Aeson hiding (encode)
import qualified Data.Aeson
+#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 T
import qualified Data.ByteString.Lazy as L
Right t -> t
Left _ -> T.pack s
+#if MIN_VERSION_aeson(2,0,0)
+textKey :: T.Text -> AK.Key
+textKey = AK.fromText
+#else
+textKey :: T.Text -> T.Text
+textKey = id
+#endif
+
-- | The same as packString . decodeBS, but more efficient in the usual
-- case.
packByteString :: S.ByteString -> T.Text