Releases: jonasbb/serde_with
serde_with v3.0.0
This breaking release should not impact most users.
It only affects custom character sets used for base64 of which there are no instances of on GitHub.
Changed
-
Upgrade base64 to v0.21 (#543)
Thanks to @jeff-hiner for submitting the PR.Remove support for custom character sets.
This is technically a breaking change.
A code search on GitHub revealed no instances of anyone using that, andserde_with
ships with many predefined character sets.
The removal means that future base64 upgrade will no longer be breaking changes.
serde_with v2.3.3
Changed
- Update
syn
to v2 anddarling
to v0.20 (#578)
Update proc-macro dependencies.
This change should have no impact on users, but now uses the same dependency asserde_derive
.
serde_with v2.3.2
Changed
-
Improve the error message when deserializing
OneOrMany
orPickFirst
fails.
It now includes the original error message for each of the individual variants.
This is possible by dropping untagged enums as the internal implementations, since they will likely never support this, as these old PRs show serde#2376 and serde#1544.The new errors look like:
OneOrMany could not deserialize any variant: One: invalid type: map, expected u32 Many: invalid type: map, expected a sequence
PickFirst could not deserialize any variant: First: invalid type: string "Abc", expected u32 Second: invalid digit found in string
Fixed
serde_with v2.3.1
Fixed
-
Undo the changes to the trait bound for
Seq
. (#570, #571)
The new implementation caused issues with serialization formats that require the sequence length beforehand.
It also caused problems, that certain attributes which worked before no longer worked, due to mismatching number of references.Thanks to @stefunctional for reporting and for @stephaneyfx for providing a test case.
serde_with v2.3.0
Added
-
Add
serde_as
compatible versions for the existing duplicate key and value handling. (#534)
The new typesMapPreventDuplicates
,MapFirstKeyWins
,SetPreventDuplicates
, andSetLastValueWins
can replace the existing modulesmaps_duplicate_key_is_error
,maps_first_key_wins
,sets_duplicate_value_is_error
, andsets_last_value_wins
. -
Added a new
KeyValueMap
type using the map key as a struct field. (#341)
This conversion is useful for maps, where an ID value is the map key, but the ID should become part of a single struct.
The conversion allows this, by using a special field named$key$
.This conversion is possible for structs and maps, using the
$key$
field.
Tuples, tuple structs, and sequences are supported by turning the first value into the map key.Each of the
SimpleStruct
s// Somewhere there is a collection: // #[serde_as(as = "KeyValueMap<_>")] // Vec<SimpleStruct>, #[derive(Serialize, Deserialize)] struct SimpleStruct { b: bool, // The field named `$key$` will become the map key #[serde(rename = "$key$")] id: String, i: i32, }
will turn into a JSON snippet like this.
"id-0000": { "b": false, "i": 123 },
Changed
- Relax the trait bounds of
Seq
to allow for more custom types. (#565)
This extends the support beyond tuples.
Fixed
EnumMap
passes thehuman_readable
status of theSerializer
to more places.- Support
alloc
on targets withouttarget_has_atomic = "ptr"
. (#560)
Thanks to @vembacher for reporting and fixing the issue.
serde_with v2.2.0
Added
-
Add new
Map
andSeq
types for converting between maps and tuple lists. (#527)The behavior is not new, but already present using
BTreeMap
/HashMap
orVec
.
However, the new typesMap
andSeq
are also available onno_std
, even without thealloc
feature.
Changed
- Pin the
serde_with_macros
dependency to the same version as the main crate.
This simplifies publishing and ensures that always a compatible version is picked.
Fixed
serde_with::apply
had an issue matching types when invisible token groups where in use (#538)
The token groups can stem from macro_rules expansion, but should be treated mostly transparent.
The old code required a group to match a group, while now groups are silently removed when checking for type patterns.
serde_with v2.1.0
Added
-
Add new
apply
attribute to simplify repetitive attributes over many fields.
Multiple rules and multiple attributes can be provided each.#[serde_with::apply( Option => #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")], Option<bool> => #[serde(rename = "bool")], )] #[derive(serde::Serialize)] struct Data { a: Option<String>, b: Option<u64>, c: Option<String>, d: Option<bool>, }
The
apply
attribute will expand into this, applying the attributs to the matching fields:#[derive(serde::Serialize)] struct Data { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] a: Option<String>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] b: Option<u64>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] c: Option<String>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "bool")] d: Option<bool>, }
The attribute supports field matching using many rules, such as
_
to apply to all fields and partial generics likeOption
to match anyOption
be itOption<String>
,Option<bool>
, orOption<T>
.
Fixed
serde_with_macros v2.1.0
Added
-
Add new
apply
attribute to simplify repetitive attributes over many fields.
Multiple rules and multiple attributes can be provided each.#[serde_with::apply( Option => #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")], Option<bool> => #[serde(rename = "bool")], )] #[derive(serde::Serialize)] struct Data { a: Option<String>, b: Option<u64>, c: Option<String>, d: Option<bool>, }
The
apply
attribute will expand into this, applying the attributs to the matching fields:#[derive(serde::Serialize)] struct Data { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] a: Option<String>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] b: Option<u64>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] c: Option<String>, #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "bool")] d: Option<bool>, }
The attribute supports field matching using many rules, such as
_
to apply to all fields and partial generics likeOption
to match anyOption
be itOption<String>
,Option<bool>
, orOption<T>
.
Fixed
serde_with v2.0.1
Added
time
added support for the well-knownIso8601
format.
This extends the existing support ofRfc2822
andRfc3339
.
Changed
- Warn if
serde_as
is used on an enum variant.
Attributes on enum variants were never supported.
But#[serde(with = "...")]
can be added on variants, such that some confusion can occur when migration (#499).
Note
A cargo bug (cargo#10801) means that upgrading from v1 to v2 may add unnecessary crates to the Cargo.lock
file.
A diff of the lock-file makes it seem that serde_with
depends on new crates, even though these crates are unused and will not get compiled or linked.
However, tools consuming Cargo.lock
or cargo metadata
might give wrong results.
serde_with_macros v2.0.1
Changed
- Warn if
serde_as
is used on an enum variant.
Attributes on enum variants were never supported.
But#[serde(with = "...")]
can be added on variants, such that some confusion can occur when migration (#499).