From ff05fa3fab535df6610ce4df21162fc676f098f0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 21 Jan 2016 09:12:50 +0000 Subject: Added json instances to api --- spec/src/Thermoprint/API.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/src/Thermoprint/API.hs') 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 import Data.Set (Set) import Data.Map (Map) +import qualified Data.Map as Map (foldMapWithKey, singleton) import Data.Sequence (Seq) +import Data.IntMap.Strict (IntMap) +import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) + import Data.Text (Text) import GHC.Generics (Generic) @@ -33,6 +37,13 @@ import Data.Proxy (Proxy(..)) import Control.Exception (Exception) import Data.Typeable (Typeable) +instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where + toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) + +instance (Enum k, Ord k, FromJSON v) => FromJSON (Map k v) where + parseJSON = fmap (IntMap.foldMapWithKey $ Map.singleton . castId) . parseJSON + + data PrinterStatus = Busy JobId | Available deriving (Generic, Show, FromJSON, ToJSON) -- cgit v1.2.3