chrono
                                
                                 chrono copied to clipboard
                                
                                    chrono copied to clipboard
                            
                            
                            
                        How to Deserialize a Vec<DateTime<Utc>> with ts_seconds
Hi, how can I apply serde with to a `Vec<DateTime<Utc>>?
You can write this to deserialize a Vec<DateTime<Utc>>.
#[serde_with::serde_as]
#[derive(serde::Deserialize)]
#[serde(transparent)]
struct Wrapper(
    #[serde_as(as = "Vec<serde_with::TimestampSeconds<i64>>")]
    Vec<DateTime<Utc>>
);
let j = r#"[
    1000000000,
    2000000000,
    0,
    -1000000000,
    -1500000000
]"#;
let Wrapper(vdt) = serde_json::from_str(&j)?;
dbg!(vdt);
// Prints:
// [src/lib.rs:1] vdt = [
//     2001-09-09T01:46:40Z,
//     2033-05-18T03:33:20Z,
//     1970-01-01T00:00:00Z,
//     1938-04-24T22:13:20Z,
//     1922-06-20T21:20:00Z,
// ]
If you want to use ts_seconds you can use a wrapper around DateTime<Utc>:
#[derive(serde::Deserialize)]
#[serde(transparent)]
struct Wrapper(
    #[serde(with = "ts_seconds")]
    DateTime<Utc>
);
let tmp: Vec<Wrapper> = serde_json::from_str(&j)?;
let vdt: Vec<DateTime<Utc>> = tmp.into_iter().map(|Wrapper(x)| x).collect();