zefchain / serde-reflection

Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.
Apache License 2.0
124 stars 22 forks source link

[Bug] Error will be reported when "chrono" type is defined #23

Closed guoyucode closed 1 year ago

guoyucode commented 1 year ago

🐛 Bug

[derive(Serialize, Deserialize, Default)]

pub struct A { pub created_at: chrono::NaiveDateTime, pub xxx: i64, }

let mut tracer = serde_reflection::Tracer::new(serde_reflection::TracerConfig::default()); let mut samples = serde_reflection::Samples::new(); tracer.trace_type::(&mut samples).unwrap(); let registry = tracer.registry().unwrap(); serde_json::to_string_pretty(&registry).unwrap_or_default();

error message alert: on an Err value: Custom("Failed to deserialize value: \"premature end of input\"")'

ma2bd commented 1 year ago

The default implementation of Serialize and Deserialize for chrono::NaiveDataTime is not working with serde_reflection but you may use the with-annotations provided by chrono::naive::serde.

For instance#[serde(with = "ts_microseconds")] https://docs.rs/chrono/latest/chrono/naive/serde/ts_microseconds/index.html