Deserialize unix timestamps into `chrono::NaiveDateTime`
Closed this issue · 1 comments
mWalrus commented
Hi, I'm stuck trying to deserialize the graphql response for one of my queries at work.
I have this query:
thing {
...
approvalStatus {
status
date
}
...
}
The query returns the following json:
"thing": {
...
"approvalStatus": {
"status": "",
"date": 0
}
...
}
When trying to deserialize date
into a NaiveDateTime it errors with a "invalid type: integer 0
, expected a formatted date and time string" message. Is there any way for me to specify that I want to deserialize date(time) fields using chrono's chrono::naive::serde::ts_milliseconds
for example?
mWalrus commented
I solved this by creating a wrapper type which I then use with the query:
#[derive(Deserialize, Debug)]
pub struct DateTime(#[serde(with = "ts_milliseconds_option")] pub Option<NaiveDateTime>);