module AlBhed.JSON
(
) where
import Data.Aeson
import Data.Aeson.Encoding
import qualified Data.Scientific as Scientific (toBoundedInteger)
import Text.Casing
import AlBhed
instance ToJSON Volume where
toJSON = Number . fromIntegral . (+1) . fromEnum
toEncoding = int . (+1) . fromEnum
instance FromJSON Volume where
parseJSON (Number x) =
let maybeVolume = Scientific.toBoundedInteger x >>= toVolume
in case maybeVolume of
Just vol -> pure vol
Nothing -> fail "Volume number is out of bounds"
parseJSON _ = fail "Volume must be a number"
instance ToJSON Primer where
toEncoding = genericToEncoding defaultOptions { fieldLabelModifier = camel . drop 6 }
instance FromJSON Primer where
parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = camel . drop 6 }