JTWT45BHSCSNVFFUW4OXPUHEV7OTC4SMME7PFBEYPBW66G5DZBGAC
N6QJ236Y2AZPEGARYA2KRQ7USHCJ5FK3WPJE6KWMCCK2KEQMTA7AC
E7PCIWPUOIVD55VKTKRQ6CB2TNEHXRG5KSEHXXBDF7KUR3YH4QQAC
DT2CHVIEWBPILKXBYFYT6C3C3BOADG6ITIUXYY6VMQU7EFT6S6JQC
44B3SUXR4SUE7PO34G7RMVQWHH4G6X342OZ3RZURV6JJQPHOJZZAC
W65GMUVA7GT5Z5ZD5YIWSMVZK42TBY7CHQ5GQRQQ244ULZ4GF2HQC
J7LSWCNFU3UWTUXFHQLIRLW2BHXJA54AT6SR5JY6JK3XABO4ZIXQC
2VCC6DPGXLR6KYEW5NOLKPE6TXWHY5M6B74ZRZBU6IP3LZQDGCXQC
B2JWXIEPCMVVITDJDR2SACY4VHITXGH7ZM6A5RWN6E7OKTO43TUAC
instance ToJSON Volume where
toJSON = Number . fromIntegral . fromVolume
toEncoding = int . fromVolume
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 jsonOptions
instance FromJSON Primer where
parseJSON = genericParseJSON jsonOptions
module AlBhed.JSON
(
) where
import Data.Aeson
import Data.Aeson.Encoding
import Data.JSON
import qualified Data.Scientific as Scientific (toBoundedInteger)
import AlBhed
instance ToJSON Volume where
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
instance FromJSON Primer where
parseJSON = genericParseJSON jsonOptions
toEncoding = genericToEncoding jsonOptions
toJSON = Number . fromIntegral . fromVolume
toEncoding = int . fromVolume