Releases: jonasbb/serde_with
serde_with v1.12.1
serde_with_macros v1.5.2
serde_with v1.12.0
Added
-
Deserialize a
Vec
and skip all elements failing to deserialize #383VecSkipError
acts like aVec
, but elements which fail to deserialize, like the"Yellow"
are ignored.#[derive(serde::Deserialize)] enum Color { Red, Green, Blue, } // JSON "colors": ["Blue", "Yellow", "Green"], // Rust #[serde_as(as = "VecSkipError<_>")] colors: Vec<Color>, // => vec![Blue, Green]
Thanks to @hdhoang for creating the PR.
-
Transform between maps and
Vec<Enum>
#375The new
EnumMap
type convertsVec
of enums into a single map.
The key is the enum variant name, and the value is the variant value.// Rust VecEnumValues(vec![ EnumValue::Int(123), EnumValue::String("Foo".to_string()), EnumValue::Unit, EnumValue::Tuple(1, "Bar".to_string()), EnumValue::Struct { a: 666, b: "Baz".to_string(), }, ] // JSON { "Int": 123, "String": "Foo", "Unit": null, "Tuple": [ 1, "Bar", ], "Struct": { "a": 666, "b": "Baz", } }
Changed
- The
Timestamp*Seconds
andTimestamp*SecondsWithFrac
types can now be used withchrono::NaiveDateTime
. #389
serde_with v1.11.0
Added
-
Serialize bytes as base64 encoded strings.
The character set and padding behavior can be configured.// Rust #[serde_as(as = "serde_with::base64::Base64")] value: Vec<u8>, #[serde_as(as = "Base64<Bcrypt, Unpadded>")] bcrypt_unpadded: Vec<u8>, // JSON "value": "SGVsbG8gV29ybGQ=", "bcrypt_unpadded": "QETqZE6eT07wZEO",
-
The minimal supported Rust version (MSRV) is now specified in the
Cargo.toml
via therust-version
field. The field is supported in Rust 1.56 and has no effect on versions before.More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field
Fixed
- Fixed RUSTSEC-2020-0071 in the
time
v0.1 dependency, but changing the feature flags of thechrono
dependency. This should not change anything. Crates requiring theoldtime
feature ofchrono
can enable it separately.
serde_with_macros v1.5.1
Added
-
The minimal supported Rust version (MSRV) is now specified in the
Cargo.toml
via therust-version
field. The field is supported in Rust 1.56 and has no effect on versions before.More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field
serde_with v1.10.0
Added
-
Add
BorrowCow
which instructs serde to borrow data during deserialization ofCow<'_, str>
,Cow<'_, [u8]>
, orCow<'_, [u8; N]>
. (#347)
The implementation is for serde#2072 and serde#2016, about#[serde(borrow)]
not working forOption<Cow<'a, str>>
.#[serde_as] #[derive(Deserialize, Serialize)] struct Data<'a> { #[serde_as(as = "Option<[BorrowCow; 1]>")] nested: Option<[Cow<'a, str>; 1]>, }
The
#[serde(borrow)]
annotation is automatically added by the#[serde_as]
attribute.
Changed
- Bump MSRV to 1.46, since the dev-dependency bitflags requires that version now.
flattened_maybe!
no longer requires theserde_with
crate to be available with a specific name.
This allows renaming the crate or usingflattened_maybe!
through a re-export without any complications.
serde_with_macros v1.5.0
Added
- Add the attribute
#[serde(borrow)]
on a field ifserde_as
is used in combination with theBorrowCow
type.
serde_with v1.9.4
Fixed
-
with_prefix!
now supports an optional visibility modifier. (#327, #328)
If not specifiedpub(self)
is assumed.with_prefix!(prefix_active "active_"); // => mod {...} with_prefix!(pub prefix_active "active_"); // => pub mod {...} with_prefix!(pub(crate) prefix_active "active_"); // => pub(crate) mod {...} with_prefix!(pub(in other_mod) prefix_active "active_"); // => pub(in other_mod) mod {...}
Thanks to @elpiel for raising and fixing the issue.
serde_with v1.9.3
Added
-
The
Bytes
type now supports borrowed and Cow arrays of fixed size (requires Rust 1.51+)#[serde_as(as = "Bytes")] #[serde(borrow)] borrowed_array: &'a [u8; 15], #[serde_as(as = "Bytes")] #[serde(borrow)] cow_array: Cow<'a, [u8; 15]>,
Note: For borrowed arrays the used Deserializer needs to support Serde's 0-copy deserialization.
serde_with v1.9.2
Fixed
- Suppress clippy warnings, which can occur while using
serde_conv
(#320)
Thanks to @mkroening for reporting and fixing the issue.