Revision 88b58ed6 src/Ganeti/JSON.hs

b/src/Ganeti/JSON.hs
48 48
  , HasStringRepr(..)
49 49
  , GenericContainer(..)
50 50
  , Container
51
  , MaybeForJSON(..)
51 52
  )
52 53
  where
53 54

  
......
288 289
  readJSON (J.JSObject o) = readContainer o
289 290
  readJSON v = fail $ "Failed to load container, expected object but got "
290 291
               ++ show (pp_value v)
292

  
293
-- | A Maybe newtype that allows for serialization more appropriate to the
294
-- semantics of Maybe and JSON in our calls. Does not produce needless
295
-- and confusing dictionaries.
296
newtype MaybeForJSON a = MaybeForJSON { unMaybeForJSON :: Maybe a }
297
instance (J.JSON a) => J.JSON (MaybeForJSON a) where
298
  readJSON = J.readJSON
299
  showJSON (MaybeForJSON (Just x)) = J.showJSON x
300
  showJSON (MaybeForJSON Nothing)  = J.JSNull

Also available in: Unified diff