summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 19:50:02 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 19:50:02 -0400
commitc4da1f5244b506a36c129dc577ba777b78b486c7 (patch)
tree3b13f2e0f0f7f9bd28fd4a7d54ffb6dba294c9dd /Types
parentbcc5ee4f322a139ee7cef2bae1fc9bea9f5398ca (diff)
improved use of Aeson for JSONActionItem
Diffstat (limited to 'Types')
-rw-r--r--Types/Key.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/Types/Key.hs b/Types/Key.hs
index 8c1828c7e..3642eca1c 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -1,6 +1,6 @@
{- git-annex Key data type
-
- - Copyright 2011-2014 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -21,6 +21,8 @@ module Types.Key (
) where
import System.Posix.Types
+import Data.Aeson
+import qualified Data.Text as T
import Common
import Utility.QuickCheck
@@ -120,6 +122,13 @@ file2key s
_ -> return k
addfield _ _ _ = Nothing
+instance ToJSON Key where
+ toJSON = toJSON . key2file
+
+instance FromJSON Key where
+ parseJSON (String t) = maybe mempty pure $ file2key $ T.unpack t
+ parseJSON _ = mempty
+
instance Arbitrary Key where
arbitrary = Key
<$> (listOf1 $ elements $ ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "-_\r\n \t")