jonasbb/serde_with
### [`v2.3.2`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.2): serde_with v2.3.2
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.3.1...v2.3.2)
##### Changed
- Improve the error message when deserializing `OneOrMany` or `PickFirst` 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](https://togithub.com/serde-rs/serde/pull/2376) and [serde#1544](https://togithub.com/serde-rs/serde/pull/1544).
The new errors look like:
```text
OneOrMany could not deserialize any variant:
One: invalid type: map, expected u32
Many: invalid type: map, expected a sequence
```
```text
PickFirst could not deserialize any variant:
First: invalid type: string "Abc", expected u32
Second: invalid digit found in string
```
##### Fixed
- Specify the correct minimum serde version as dependency. ([#588](https://togithub.com/jonasbb/serde_with/issues/588))
Thanks to [@nox](https://togithub.com/nox) for submitting a PR.
### [`v2.3.1`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.1): serde_with v2.3.1
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.3.0...v2.3.1)
##### Fixed
- Undo the changes to the trait bound for `Seq`. ([#570](https://togithub.com/jonasbb/serde_with/issues/570), [#571](https://togithub.com/jonasbb/serde_with/issues/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](https://togithub.com/stefunctional) for reporting and for [@stephaneyfx](https://togithub.com/stephaneyfx) for providing a test case.
### [`v2.3.0`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.0): serde_with v2.3.0
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.2.0...v2.3.0)
##### Added
- Add `serde_as` compatible versions for the existing duplicate key and value handling. ([#534](https://togithub.com/jonasbb/serde_with/issues/534))
The new types `MapPreventDuplicates`, `MapFirstKeyWins`, `SetPreventDuplicates`, and `SetLastValueWins` can replace the existing modules `maps_duplicate_key_is_error`, `maps_first_key_wins`, `sets_duplicate_value_is_error`, and `sets_last_value_wins`.
- Added a new `KeyValueMap` type using the map key as a struct field. ([#341](https://togithub.com/jonasbb/serde_with/issues/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
```rust
// Somewhere there is a collection:
// #[serde_as(as = "KeyValueMap<_>")]
// Vec,
#[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.
```json
"id-0000": {
"b": false,
"i": 123
},
```
##### Changed
- Relax the trait bounds of `Seq` to allow for more custom types. ([#565](https://togithub.com/jonasbb/serde_with/issues/565))
This extends the support beyond tuples.
##### Fixed
- `EnumMap` passes the `human_readable` status of the `Serializer` to more places.
- Support `alloc` on targets without `target_has_atomic = "ptr"`. ([#560](https://togithub.com/jonasbb/serde_with/issues/560))
Thanks to [@vembacher](https://togithub.com/vembacher) for reporting and fixing the issue.
### [`v2.2.0`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.2.0): serde_with v2.2.0
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.1.0...v2.2.0)
##### Added
- Add new `Map` and `Seq` types for converting between maps and tuple lists. ([#527](https://togithub.com/jonasbb/serde_with/issues/527))
The behavior is not new, but already present using `BTreeMap`/`HashMap` or `Vec`.
However, the new types `Map` and `Seq` are also available on `no_std`, even without the `alloc` 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](https://togithub.com/jonasbb/serde_with/issues/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.
### [`v2.1.0`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.1.0): serde_with v2.1.0
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.0.1...v2.1.0)
##### Added
- Add new `apply` attribute to simplify repetitive attributes over many fields.
Multiple rules and multiple attributes can be provided each.
```rust
#[serde_with::apply(
Option => #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")],
Option => #[serde(rename = "bool")],
)]
#[derive(serde::Serialize)]
struct Data {
a: Option,
b: Option,
c: Option,
d: Option,
}
```
The `apply` attribute will expand into this, applying the attributs to the matching fields:
```rust
#[derive(serde::Serialize)]
struct Data {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
a: Option,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
b: Option,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
c: Option,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "bool")]
d: Option,
}
```
The attribute supports field matching using many rules, such as `_` to apply to all fields and partial generics like `Option` to match any `Option` be it `Option`, `Option`, or `Option`.
##### Fixed
- The derive macros `SerializeDisplay` and `DeserializeFromStr` now take better care not to use conflicting names for generic values. ([#526](https://togithub.com/jonasbb/serde_with/issues/526))
All used generics now start with `__` to make conflicts with manually written code unlikely.
Thanks to [@Elrendio](https://togithub.com/Elrendio) for submitting a PR fixing the issue.
### [`v2.0.1`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.0.1): serde_with v2.0.1
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.0.0...v2.0.1)
##### Added
- `time` added support for the well-known `Iso8601` format.
This extends the existing support of `Rfc2822` and `Rfc3339`.
##### 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](https://togithub.com/jonasbb/serde_with/issues/499)).
##### Note
A cargo bug ([cargo#10801](https://togithub.com/rust-lang/cargo/issues/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.
### [`v2.0.0`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.0.0): serde_with v2.0.0
[Compare Source](https://togithub.com/jonasbb/serde_with/compare/v1.14.0...v2.0.0)
##### Added
- Make `JsonString` smarter by allowing nesting `serde_as` definitions.
This allows applying custom serialization logic, before the value gets converted into a JSON string.
```rust
// Rust
#[serde_as(as = "JsonString>")]
value: BTreeMap<[u8; 2], u32>,
// JSON
{"value":"[[\"[1,2]\",3],[\"[4,5]\",6]]"}
```
##### Changed
- Make `#[serde_as]` behave more intuitive on `Option` fields.
The `#[serde_as]` macro now detects if a `#[serde_as(as = "Option")]` is used on a field of type `Option` and applies `#[serde(default)]` to the field.
This restores the ability to deserialize with missing fields and fixes a common annoyance ([#183](https://togithub.com/jonasbb/serde_with/issues/183), [#185](https://togithub.com/jonasbb/serde_with/issues/185), [#311](https://togithub.com/jonasbb/serde_with/issues/311), [#417](https://togithub.com/jonasbb/serde_with/issues/417)).
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired.
The `Option` field and transformation are detected by directly matching on the type name.
These variants are detected as `Option`.
- `Option`
- `std::option::Option`, with or without leading `::`
- `core::option::Option`, with or without leading `::`
If an existing `default` attribute is detected, the attribute is not applied again.
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option", no_default)]`.
- `NoneAsEmptyString` and `string_empty_as_none` use a different serialization bound ([#388](https://togithub.com/jonasbb/serde_with/issues/388)).
Both types used `AsRef` as the serialization bound.
This is limiting for non-string types like `Option`.
The deserialization often was already more flexible, due to the `FromStr` bound.
For most std types this should have little impact, as the types implementing `AsRef` mostly implement `Display`, too, such as `String`, `Cow`, or `Rc`.
- Bump MSRV to 1.60. This is required for the optional dependency feature syntax in cargo.
##### Removed
- Remove old module based conversions.
The newer `serde_as` based conversions are preferred.
- `seq_display_fromstr`: Use `DisplayFromStr` in combination with your container type:
```rust
#[serde_as(as = "BTreeSet")]
addresses: BTreeSet,
#[serde_as(as = "Vec")]
bools: Vec,
```
- `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples:
```rust
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work
s: Vec<(i32, String)>,
```
- `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
- `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`.
- `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`.
- `default_on_error` can be replaced with `#[serde_as(as = "DefaultOnError")]`.
- `default_on_null` can be replaced with `#[serde_as(as = "DefaultOnNull")]`.
- `string_empty_as_none` can be replaced with `#[serde_as(as = "NoneAsEmptyString")]`.
- `StringWithSeparator` can now only be used in `serde_as`.
The definition of the `Separator` trait and its implementations have been moved to the `formats` module.
- `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`.
- Remove previously deprecated modules.
- `sets_first_value_wins`
- `btreemap_as_tuple_list` and `hashmap_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
[ ] If you want to rebase/retry this PR, check this box
This PR has been generated by Mend Renovate. View repository job log here.
This PR contains the following updates:
1.14
->2.3
Release Notes
jonasbb/serde_with
### [`v2.3.2`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.2): serde_with v2.3.2 [Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.3.1...v2.3.2) ##### Changed - Improve the error message when deserializing `OneOrMany` or `PickFirst` 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](https://togithub.com/serde-rs/serde/pull/2376) and [serde#1544](https://togithub.com/serde-rs/serde/pull/1544). The new errors look like: ```text OneOrMany could not deserialize any variant: One: invalid type: map, expected u32 Many: invalid type: map, expected a sequence ``` ```text PickFirst could not deserialize any variant: First: invalid type: string "Abc", expected u32 Second: invalid digit found in string ``` ##### Fixed - Specify the correct minimum serde version as dependency. ([#588](https://togithub.com/jonasbb/serde_with/issues/588)) Thanks to [@nox](https://togithub.com/nox) for submitting a PR. ### [`v2.3.1`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.1): serde_with v2.3.1 [Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.3.0...v2.3.1) ##### Fixed - Undo the changes to the trait bound for `Seq`. ([#570](https://togithub.com/jonasbb/serde_with/issues/570), [#571](https://togithub.com/jonasbb/serde_with/issues/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](https://togithub.com/stefunctional) for reporting and for [@stephaneyfx](https://togithub.com/stephaneyfx) for providing a test case. ### [`v2.3.0`](https://togithub.com/jonasbb/serde_with/releases/tag/v2.3.0): serde_with v2.3.0 [Compare Source](https://togithub.com/jonasbb/serde_with/compare/v2.2.0...v2.3.0) ##### Added - Add `serde_as` compatible versions for the existing duplicate key and value handling. ([#534](https://togithub.com/jonasbb/serde_with/issues/534)) The new types `MapPreventDuplicates`, `MapFirstKeyWins`, `SetPreventDuplicates`, and `SetLastValueWins` can replace the existing modules `maps_duplicate_key_is_error`, `maps_first_key_wins`, `sets_duplicate_value_is_error`, and `sets_last_value_wins`. - Added a new `KeyValueMap` type using the map key as a struct field. ([#341](https://togithub.com/jonasbb/serde_with/issues/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 ```rust // Somewhere there is a collection: // #[serde_as(as = "KeyValueMap<_>")] // Vec")]` is used on a field of type `Option` and applies `#[serde(default)]` to the field.
This restores the ability to deserialize with missing fields and fixes a common annoyance ([#183](https://togithub.com/jonasbb/serde_with/issues/183), [#185](https://togithub.com/jonasbb/serde_with/issues/185), [#311](https://togithub.com/jonasbb/serde_with/issues/311), [#417](https://togithub.com/jonasbb/serde_with/issues/417)).
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired.
The `Option` field and transformation are detected by directly matching on the type name.
These variants are detected as `Option`.
- `Option`
- `std::option::Option`, with or without leading `::`
- `core::option::Option`, with or without leading `::`
If an existing `default` attribute is detected, the attribute is not applied again.
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option ", no_default)]`. - `NoneAsEmptyString` and `string_empty_as_none` use a different serialization bound ([#388](https://togithub.com/jonasbb/serde_with/issues/388)). Both types used `AsRef` as the serialization bound.
This is limiting for non-string types like `Option`.
The deserialization often was already more flexible, due to the `FromStr` bound.
For most std types this should have little impact, as the types implementing `AsRef` mostly implement `Display`, too, such as `String`, `Cow`, or `Rc`.
- Bump MSRV to 1.60. This is required for the optional dependency feature syntax in cargo.
##### Removed
- Remove old module based conversions.
The newer `serde_as` based conversions are preferred.
- `seq_display_fromstr`: Use `DisplayFromStr` in combination with your container type:
```rust
#[serde_as(as = "BTreeSet")]
addresses: BTreeSet,
#[serde_as(as = "Vec")]
bools: Vec,
```
- `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples:
```rust
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work
s: Vec<(i32, String)>,
```
- `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
- `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`.
- `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`.
- `default_on_error` can be replaced with `#[serde_as(as = "DefaultOnError")]`.
- `default_on_null` can be replaced with `#[serde_as(as = "DefaultOnNull")]`.
- `string_empty_as_none` can be replaced with `#[serde_as(as = "NoneAsEmptyString")]`.
- `StringWithSeparator` can now only be used in `serde_as`.
The definition of the `Separator` trait and its implementations have been moved to the `formats` module.
- `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`.
- Remove previously deprecated modules.
- `sets_first_value_wins`
- `btreemap_as_tuple_list` and `hashmap_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.