We need to implment our own Deserializer
in this situation:
pub struct Suggection {
pub id: i32,
pub title: String,
pub content: Option<String>,
pub principal: String,
#[serde(with = "timestamp_format")]
pub created_at: time::OffsetDateTime,
}
mod timestamp_format {
use candid::Deserialize;
use serde::de::Error as SerdeError;
use serde::{Deserializer, Serializer};
use time::PrimitiveDateTime;
use time::{Duration, OffsetDateTime};
pub fn deserialize<'de, D>(deserializer: D) -> Result<OffsetDateTime, D::Error>
where
D: Deserializer<'de>,
{
let timestamp = u128::deserialize(deserializer)?;
Ok(OffsetDateTime::from_unix_timestamp_nanos(timestamp.try_into().unwrap()).unwrap())
}
}