Last active: 10 months ago
deserialize with custom function
fn de_str<'de, D>(deserializer: D) -> Result<i64, D::Error>
where
D: serde::de::Deserializer<'de>,
{
Ok(match Value::deserialize(deserializer)? {
Value::String(s) => s.parse().map_err(de::Error::custom)?,
Value::Number(num) => num.as_i64().ok_or(de::Error::custom("Invalide number"))?,
_ => return Err(de::Error::custom("wrong type")),
})
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BoothExamplesList {
pub total: i64,
#[serde(deserialize_with = "de_str")]
pub per_page: i64,
pub current_page: i64,
pub last_page: i64,
pub data: Vec<BoothExamplesDatum>,
}