Respect serialize_with attr when serializing default
This commit is contained in:
parent
7e23e2ad7a
commit
b748a90c3f
6 changed files with 74 additions and 27 deletions
|
@ -2,31 +2,40 @@ mod util;
|
|||
|
||||
use other_crate::Duration;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use util::*;
|
||||
|
||||
mod other_crate {
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Duration {
|
||||
pub secs: i64,
|
||||
pub nanos: i32,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(Debug, JsonSchema, Serialize)]
|
||||
#[serde(remote = "Duration")]
|
||||
struct DurationDef {
|
||||
secs: i64,
|
||||
nanos: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
fn custom_serialize<S>(value: &Duration, ser: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
ser.collect_str(&format_args!("{}.{:09}s", value.secs, value.nanos))
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema, Serialize)]
|
||||
struct Process {
|
||||
command_line: String,
|
||||
#[serde(with = "DurationDef")]
|
||||
wall_time: Duration,
|
||||
#[serde(with = "DurationDef")]
|
||||
#[serde(default, with = "DurationDef")]
|
||||
user_cpu_time: Duration,
|
||||
#[serde(deserialize_with = "some_serialize_function")]
|
||||
// FIXME this should serialize the default as "0.000000000s"
|
||||
#[serde(default, serialize_with = "custom_serialize")]
|
||||
#[schemars(with = "DurationDef")]
|
||||
system_cpu_time: Duration,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue