diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-21 09:12:50 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-21 09:12:50 +0000 |
commit | ff05fa3fab535df6610ce4df21162fc676f098f0 (patch) | |
tree | eda3eb6233610bbb533e5af0eccde42d00e71f34 /spec | |
parent | 58d26527560f8d3e21f5f50ec9a5e993cf044ae0 (diff) | |
download | thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.gz thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.bz2 thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.xz thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.zip |
Added json instances to api
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/API.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 4b10130..6c86008 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs | |||
@@ -22,8 +22,12 @@ import Data.Aeson | |||
22 | 22 | ||
23 | import Data.Set (Set) | 23 | import Data.Set (Set) |
24 | import Data.Map (Map) | 24 | import Data.Map (Map) |
25 | import qualified Data.Map as Map (foldMapWithKey, singleton) | ||
25 | import Data.Sequence (Seq) | 26 | import Data.Sequence (Seq) |
26 | 27 | ||
28 | import Data.IntMap.Strict (IntMap) | ||
29 | import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) | ||
30 | |||
27 | import Data.Text (Text) | 31 | import Data.Text (Text) |
28 | 32 | ||
29 | import GHC.Generics (Generic) | 33 | import GHC.Generics (Generic) |
@@ -33,6 +37,13 @@ import Data.Proxy (Proxy(..)) | |||
33 | import Control.Exception (Exception) | 37 | import Control.Exception (Exception) |
34 | import Data.Typeable (Typeable) | 38 | import Data.Typeable (Typeable) |
35 | 39 | ||
40 | instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where | ||
41 | toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) | ||
42 | |||
43 | instance (Enum k, Ord k, FromJSON v) => FromJSON (Map k v) where | ||
44 | parseJSON = fmap (IntMap.foldMapWithKey $ Map.singleton . castId) . parseJSON | ||
45 | |||
46 | |||
36 | data PrinterStatus = Busy JobId | 47 | data PrinterStatus = Busy JobId |
37 | | Available | 48 | | Available |
38 | deriving (Generic, Show, FromJSON, ToJSON) | 49 | deriving (Generic, Show, FromJSON, ToJSON) |