improved use of Aeson for JSONActionItem

This commit is contained in:
Joey Hess 2016-07-26 19:50:02 -04:00
parent 870873bdaa
commit 928fbb162d
Failed to extract signature
3 changed files with 45 additions and 36 deletions

View file

@ -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")