-
-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Description
SystemTime
and Duration
are serialized as two-field objects, not strings. Instant
doesn't support serialization at all, see serde-rs/serde#1375.
[dependencies]
chrono = { version = "0.4.24", features = ["serde"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
specta = "1.0.4"
#[derive(serde::Serialize)]
#[derive(specta::Type)]
struct MyStruct {
st: std::time::SystemTime,
// i: std::time::Instant,
d: std::time::Duration,
}
fn main() {
println!("{}", specta::ts::export::<MyStruct>(&Default::default()).unwrap());
println!();
let s = MyStruct {
st: std::time::SystemTime::now(),
d: std::time::Duration::from_secs(1),
};
println!("{}", serde_json::to_string_pretty(&s).unwrap());
}
export type MyStruct = { st: string; d: string }
{
"st": {
"secs_since_epoch": 1684393811,
"nanos_since_epoch": 203204000
},
"d": {
"secs": 1,
"nanos": 0
}
}
Metadata
Metadata
Assignees
Labels
No labels