{-# LANGUAGE FlexibleContexts #-}
module Control.Restartable.Initial where
import Control.Applicative((<|>))
import Data.Aeson.Types
import GHC.Generics ( Generic(Rep) )
class (FromJSON a
,ToJSON a)
=> Initial a
initial :: Initial a => a
initial = case fromJSON Null of
Error _ -> error "Failed to initialize from empty JSON!"
Success a -> a
initially :: (Generic a, GFromJSON Zero (Rep a))
=> a -> Value -> Parser a
initially x v = genericParseJSON robustOptions v <|> pure x
robustOptions :: Options
robustOptions =
defaultOptions {
omitNothingFields = True
, allNullaryToStringTag = False
}