Revision 6879dfd2 src/Ganeti/JSON.hs
b/src/Ganeti/JSON.hs | ||
---|---|---|
313 | 313 |
-- semantics of Maybe and JSON in our calls. Does not produce needless |
314 | 314 |
-- and confusing dictionaries. |
315 | 315 |
newtype MaybeForJSON a = MaybeForJSON { unMaybeForJSON :: Maybe a } |
316 |
deriving (Show, Eq, Ord) |
|
316 | 317 |
instance (J.JSON a) => J.JSON (MaybeForJSON a) where |
317 |
readJSON = J.readJSON |
|
318 |
readJSON J.JSNull = return $ MaybeForJSON Nothing |
|
319 |
readJSON x = (MaybeForJSON . Just) `liftM` J.readJSON x |
|
318 | 320 |
showJSON (MaybeForJSON (Just x)) = J.showJSON x |
319 | 321 |
showJSON (MaybeForJSON Nothing) = J.JSNull |
320 | 322 |
|
Also available in: Unified diff