Let me post a concrete example.
Given these datatypes and FromJSON
instances
data PersonTQ = PersonTQ
{ ptqType :: PersonT
, ptqQuantity :: Int
}
deriving (Eq, Show, Generic)
instance FromJSON PersonTQ
data BookingFormResult = BookingFormResult
{ forder :: !(Maybe BookingFormOrder)
, orderId :: !(Maybe OrderId)
, persons :: [PersonTQ]
, start :: !UTCTime
, end :: !(Maybe UTCTime)
, timeZone :: !(Maybe String)
, prod :: !Int64
, platform :: !Platform
, foreignId :: !Text
, language :: !Language
, bfAddons :: [AddonBF]
}
deriving (Eq, Show, Generic)
instance FromJSON BookingFormResult
when we receive the following json
{
"timeZone": null,
"start": "2023-08-25T07:00:00Z",
"prod": 569,
"platform": "BlueMoon",
"persons": [
{
"ptqType": "Adults",
"ptqQuantity": 0.24 -- this is the issue, should be an integer!
}
],
"orderId": null,
"language": "English",
"foreignId": "",
"forder": {
"phonet": "",
"phone": "",
"lname": "zucon",
"fname": "gigi",
"email": "",
"cusnotes": null
},
"end": null,
"bfWpAddons": [],
"bfAddons": []
}
the error message we get is
Error: parsing Int failed, value is either floating or will cause over or underflow 0.24
The same happens using
$(deriveJSON defaultOptions ''PersonTQ)
$(deriveJSON defaultOptions ''BookingFormResult)
I don’t consider this a aeson
bug, but still I’d like to improve the situation of my codebase