serde_with v1.7.0
Added
-
Add support for arrays of arbitrary size. (#272)
This feature requires Rust 1.51+.// Rust #[serde_as(as = "[[_; 64]; 33]")] value: [[u8; 64]; 33], // JSON "value": [[0,0,0,0,0,...], [0,0,0,...], ...],
Mapping of arrays was available before, but limited to arrays of length 32.
All conversion methods are available for the array elements.This is similar to the existing
serde-big-array
crate with three important improvements:- Support for the
serde_as
annotation. - Supports non-copy elements (see serde-big-array#6).
- Supports arbitrary nestings of arrays (see serde-big-array#7).
- Support for the
-
Arrays with tuple elements can now be deserialized from a map. (#272)
This feature requires Rust 1.51+.// Rust #[serde_as(as = "BTreeMap<_, _>")] value: [(String, u16); 3], // JSON "value": { "a": 1, "b": 2, "c": 3 },
-
The
Bytes
type is heavily inspired byserde_bytes
and ports it to theserde_as
system. (#277)#[serde_as(as = "Bytes")] value: Vec<u8>,
Compared to
serde_bytes
these improvements are available- Integration with the
serde_as
annotation (see serde-bytes#14). - Implementation for arrays of arbitrary size (Rust 1.51+) (see serde-bytes#26).
- Integration with the
-
The
OneOrMany
allows to deserialize aVec
from either a single element or a sequence. (#281)#[serde_as(as = "OneOrMany<_>")] cities: Vec<String>,
This allows to deserialize from either
cities: "Berlin"
orcities: ["Berlin", "Paris"]
.
The serialization can be configured to always emit a list withPreferMany
or emit a single element withPreferOne
.