Skip to content

serde_with v1.14.0

Compare
Choose a tag to compare
@github-actions github-actions released this 29 May 16:52
· 574 commits to master since this release
v1.14.0
8c59954

Added

  • Add support for time crate v0.3 #450

    time::Duration can now be serialized with the DurationSeconds and related converters.

    // Rust
    #[serde_as(as = "serde_with::DurationSeconds<u64>")]
    value: Duration,
    
    // JSON
    "value": 86400,

    time::OffsetDateTime and time::PrimitiveDateTime can now be serialized with the TimestampSeconds and related converters.

    // Rust
    #[serde_as(as = "serde_with::TimestampMicroSecondsWithFrac<String>")]
    value: time::PrimitiveDateTime,
    
    // JSON
    "value": "1000000",

    time::OffsetDateTime can be serialized in string format in different well-known formats.
    Two formats are supported, time::format_description::well_known::Rfc2822 and time::format_description::well_known::Rfc3339.

    // Rust
    #[serde_as(as = "time::format_description::well_known::Rfc2822")]
    rfc_2822: OffsetDateTime,
    #[serde_as(as = "Vec<time::format_description::well_known::Rfc3339>")]
    rfc_3339: Vec<OffsetDateTime>,
    
    // JSON
    "rfc_2822": "Fri, 21 Nov 1997 09:55:06 -0600",
    "rfc_3339": ["1997-11-21T09:55:06-06:00"],
  • Deserialize bool from integers #456 462

    Deserialize an integer and convert it into a bool.
    BoolFromInt<Strict> (default) deserializes 0 to false and 1 to true, other numbers are errors.
    BoolFromInt<Flexible> deserializes any non-zero as true.
    Serialization only emits 0/1.

    // Rust
    #[serde_as(as = "BoolFromInt")] // BoolFromInt<Strict>
    b: bool,
    
    // JSON
    "b": 1,

Changed

  • Bump MSRV to 1.53, since the new dependency time requires that version.

Fixed

  • Make the documentation clearer by stating that the #[serde_as] and #[skip_serializing_none] attributes must always be places before #[derive].