| 1 |
# Changelog |
| 2 |
|
| 3 |
All notable changes to this project will be documented in this file. |
| 4 |
|
| 5 |
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) |
| 6 |
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). |
| 7 |
|
| 8 |
## [Unreleased] |
| 9 |
|
| 10 |
## [3.12.0] - 2024-12-25 |
| 11 |
|
| 12 |
### Added |
| 13 |
|
| 14 |
* Add `with_suffix!` macro, which puts a suffix on every struct field |
| 15 |
|
| 16 |
## [3.11.0] - 2024-10-05 |
| 17 |
|
| 18 |
### Added |
| 19 |
|
| 20 |
* Add support for `hashbrown` v0.15 (#787/#790) |
| 21 |
|
| 22 |
This extends the existing support for `hashbrown` v0.14 to the newly released version. |
| 23 |
|
| 24 |
## [3.10.0] - 2024-10-01 |
| 25 |
|
| 26 |
### Added |
| 27 |
|
| 28 |
* Add newline separator by @jayvdb (#777) |
| 29 |
|
| 30 |
The `UnixLineSeparator` and `DosLineSeparator` can be used together with `StringWithSeparator`. |
| 31 |
|
| 32 |
### Fixed |
| 33 |
|
| 34 |
* Proper handling of `cfg_attr` in the `serde_as` macro by @sivizius (#782) |
| 35 |
|
| 36 |
This allows to parse more valid forms of the `cfg_attr` macro, including multiple values and attribute that do not follow the `key = value` schema. |
| 37 |
|
| 38 |
## [3.9.0] - 2024-07-14 |
| 39 |
|
| 40 |
### Added |
| 41 |
|
| 42 |
* Deserialize a map` and skip all elements failing to deserialize by @johnmave126 (#763) |
| 43 |
|
| 44 |
`MapSkipError` acts like a map (`HashMap`/`BTreeMap`), but keys or values that fail to deserialize, like are ignored. |
| 45 |
|
| 46 |
For formats with heterogeneously typed maps, we can collect only the elements where both key and value are deserializable. |
| 47 |
This is also useful in conjunction to `#[serde(flatten)]` to ignore some entries when capturing additional fields. |
| 48 |
|
| 49 |
```text |
| 50 |
// JSON |
| 51 |
"value": {"0": "v0", "5": "v5", "str": "str", "10": 2}, |
| 52 |
|
| 53 |
// Rust |
| 54 |
#[serde_as(as = "MapSkipError<DisplayFromStr, _>")] |
| 55 |
value: BTreeMap<u32, String>, |
| 56 |
|
| 57 |
// Only deserializes entries with a numerical key and a string value, i.e., |
| 58 |
{0 => "v0", 5 => "v5"} |
| 59 |
``` |
| 60 |
|
| 61 |
## [3.8.3] - 2024-07-03 |
| 62 |
|
| 63 |
### Fixed |
| 64 |
|
| 65 |
* Fix compile issues when dependency `schemars_0_8` is used with the `preserve_order` features (#762) |
| 66 |
|
| 67 |
## [3.8.2] - 2024-06-30 |
| 68 |
|
| 69 |
### Changed |
| 70 |
|
| 71 |
* Bump MSRV to 1.67, since that is required for the `time` dependency. |
| 72 |
The `time` version needed to be updated for nightly compatibility. |
| 73 |
|
| 74 |
### Fixed |
| 75 |
|
| 76 |
* Implement `JsonSchemaAs` for `OneOrMany` instead of `JsonSchema` by @swlynch99 (#760) |
| 77 |
|
| 78 |
## [3.8.1] - 2024-04-28 |
| 79 |
|
| 80 |
### Fixed |
| 81 |
|
| 82 |
* Do not emit `schemars(deserialize_with = "...")` annotations, as `schemars` does not support them (#735) |
| 83 |
Thanks to @sivizius for reporting the issue. |
| 84 |
|
| 85 |
## [3.8.0] - 2024-04-24 |
| 86 |
|
| 87 |
### Added |
| 88 |
|
| 89 |
* Implement (De)Serialization for Pinned Smart Pointers by @Astralchroma (#733) |
| 90 |
* Implement `JsonSchemaAs` for `PickFirst` by @swlynch99 (#721) |
| 91 |
|
| 92 |
### Changed |
| 93 |
|
| 94 |
* Bump `base64` dependency to v0.22 (#724) |
| 95 |
* Update dev dependencies |
| 96 |
|
| 97 |
### Fixed |
| 98 |
|
| 99 |
* `serde_conv` regressed and triggered `clippy::ptr_arg` and add test to prevent future problems. (#731) |
| 100 |
|
| 101 |
## [3.7.0] - 2024-03-11 |
| 102 |
|
| 103 |
### Added |
| 104 |
|
| 105 |
* Implement `JsonSchemaAs` for `EnumMap` by @swlynch99 (#697) |
| 106 |
* Implement `JsonSchemaAs` for `IfIsHumanReadable` by @swlynch99 (#717) |
| 107 |
* Implement `JsonSchemaAs` for `KeyValueMap` by @swlynch99 (#713) |
| 108 |
* Implement `JsonSchemaAs` for `OneOrMany` by @swlynch99 (#719) |
| 109 |
|
| 110 |
### Fixed |
| 111 |
|
| 112 |
* Detect conflicting `schema_with` attributes on fields with `schemars` annotations by @swlynch99 (#715) |
| 113 |
This extends the existing avoidance mechanism to a new variant fixing #712. |
| 114 |
|
| 115 |
## [3.6.1] - 2024-02-08 |
| 116 |
|
| 117 |
### Changed |
| 118 |
|
| 119 |
* Eliminate dependency on serde's "derive" feature by @dtolnay (#694) |
| 120 |
This allows parallel compilation of `serde` and `serde_derive` which can speed up the wallclock time. |
| 121 |
It requires that downstream crates do not use the "derive" feature either. |
| 122 |
|
| 123 |
## [3.6.0] - 2024-01-30 |
| 124 |
|
| 125 |
### Added |
| 126 |
|
| 127 |
* Add `IfIsHumanReadable` for conditional implementation by @irriden (#690) |
| 128 |
Used to specify different transformations for text-based and binary formats. |
| 129 |
* Add more `JsonSchemaAs` impls for all `Duration*` and `Timestamp*` adaptors by @swlynch99 (#685) |
| 130 |
|
| 131 |
### Changed |
| 132 |
|
| 133 |
* Bump MSRV to 1.65, since that is required for the `regex` dependency. |
| 134 |
|
| 135 |
## [3.5.1] - 2024-01-23 |
| 136 |
|
| 137 |
### Fixed |
| 138 |
|
| 139 |
* The `serde_as` macro now better detects existing `schemars` attributes on fields and incorporates them (#682) |
| 140 |
This avoids errors on existing `#[schemars(with = ...)]` annotations. |
| 141 |
|
| 142 |
## [3.5.0] - 2024-01-20 |
| 143 |
|
| 144 |
### Added |
| 145 |
|
| 146 |
* Support for `schemars` integration added by @swlynch99 (#666) |
| 147 |
The support uses a new `Schema` top-level item which implements `JsonSchema` |
| 148 |
The `serde_as` macro can now detect `schemars` usage and emits matching annotations for all fields with `serde_as` attribute. |
| 149 |
Many types of this crate come already with support for the `schemars`, but support is not complete and will be extended over time. |
| 150 |
|
| 151 |
## [3.4.0] - 2023-10-17 |
| 152 |
|
| 153 |
* Lower minimum required serde version to 1.0.152 (#653) |
| 154 |
Thanks to @banool for submitting the PR. |
| 155 |
|
| 156 |
This allows people that have a problem with 1.0.153 to still use `serde_with`. |
| 157 |
* Add support for `core::ops::Bound` (#655) |
| 158 |
Thanks to @qsantos for submitting the PR. |
| 159 |
|
| 160 |
## [3.3.0] - 2023-08-19 |
| 161 |
|
| 162 |
### Added |
| 163 |
|
| 164 |
* Support the `hashbrown` type `HashMap` and `HashSet` (#636, #637) |
| 165 |
Thanks to @OliverNChalk for raising the issue and submitting a PR. |
| 166 |
|
| 167 |
This extends the existing support for `HashMap`s and `HashSet`s to the `hashbrown` crate v0.14. |
| 168 |
The same conversions as for the `std` and `indexmap` types are available, like general support for `#[serde_as]` and converting it to/from sequences or maps. |
| 169 |
|
| 170 |
### Changed |
| 171 |
|
| 172 |
* Generalize some trait bounds for `DeserializeAs` implementations |
| 173 |
|
| 174 |
While working on #637, it came to light that some macros for generating `DeserializeAs` implementations were not as generic as they could. |
| 175 |
This means they didn't work with custom hasher types, but only the default hashers. |
| 176 |
This has now been fixed and custom hashers should work better, as long as they implement `BuildHasher + Default`. |
| 177 |
|
| 178 |
* (internal) Change how features are documented (#639) |
| 179 |
|
| 180 |
This change moves the feature documentation into `Cargo.toml` in a format that can be read by lib.rs. |
| 181 |
It will improve the generated features documentation there. |
| 182 |
The page with all features remains in the guide but is now generated from the `Cargo.toml` information. |
| 183 |
|
| 184 |
## [3.2.0] - 2023-08-04 |
| 185 |
|
| 186 |
### Added |
| 187 |
|
| 188 |
* Add optional support for indexmap v2 (#621) |
| 189 |
Support for v1 is already available using the `indexmap_1` feature. |
| 190 |
This adds identical support for v2 of indexmap using the `indexmap_2` feature. |
| 191 |
|
| 192 |
### Changed |
| 193 |
|
| 194 |
* Bump MSRV to 1.64, since that is required for the indexmap v2 dependency. |
| 195 |
|
| 196 |
### Fixed |
| 197 |
|
| 198 |
* Prevent panics when deserializing `i64::MIN` using `TimestampSeconds<i64>` (#632, #633) |
| 199 |
Thanks to @hollmmax for reporting and fixing the issue. |
| 200 |
|
| 201 |
## [3.1.0] - 2023-07-17 |
| 202 |
|
| 203 |
### Added |
| 204 |
|
| 205 |
* Add `FromIntoRef` and `TryFromIntoRef` (#618) |
| 206 |
Thanks to @oblique for submitting the PR. |
| 207 |
|
| 208 |
The new types are similar to the existing `FromInto` and `TryFromInto` types. |
| 209 |
They behave different during serialization, allowing the removal of the `Clone` bound on their `SerializeAs` trait implementation |
| 210 |
|
| 211 |
### Changed |
| 212 |
|
| 213 |
* Improve documentation about cfg-gating `serde_as` (#607) |
| 214 |
* Bump MSRV to 1.61 because that is required by the crate `cfg_eval`. |
| 215 |
|
| 216 |
## [3.0.0] - 2023-05-01 |
| 217 |
|
| 218 |
This breaking release should not impact most users. |
| 219 |
It only affects custom character sets used for base64 of which there are no instances of on GitHub. |
| 220 |
|
| 221 |
### Changed |
| 222 |
|
| 223 |
* Upgrade base64 to v0.21 (#543) |
| 224 |
Thanks to @jeff-hiner for submitting the PR. |
| 225 |
|
| 226 |
Remove support for custom character sets. |
| 227 |
This is technically a breaking change. |
| 228 |
A code search on GitHub revealed no instances of anyone using that, and `serde_with` ships with many predefined character sets. |
| 229 |
The removal means that future base64 upgrade will no longer be breaking changes. |
| 230 |
|
| 231 |
## [2.3.3] - 2023-04-27 |
| 232 |
|
| 233 |
### Changed |
| 234 |
|
| 235 |
* Update `syn` to v2 and `darling` to v0.20 (#578) |
| 236 |
Update proc-macro dependencies. |
| 237 |
This change should have no impact on users, but now uses the same dependency as `serde_derive`. |
| 238 |
|
| 239 |
## [2.3.2] - 2023-04-05 |
| 240 |
|
| 241 |
### Changed |
| 242 |
|
| 243 |
* Improve the error message when deserializing `OneOrMany` or `PickFirst` fails. |
| 244 |
It now includes the original error message for each of the individual variants. |
| 245 |
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://github.com/serde-rs/serde/pull/2376) and [serde#1544](https://github.com/serde-rs/serde/pull/1544). |
| 246 |
|
| 247 |
The new errors look like: |
| 248 |
|
| 249 |
```text |
| 250 |
OneOrMany could not deserialize any variant: |
| 251 |
One: invalid type: map, expected u32 |
| 252 |
Many: invalid type: map, expected a sequence |
| 253 |
``` |
| 254 |
|
| 255 |
```text |
| 256 |
PickFirst could not deserialize any variant: |
| 257 |
First: invalid type: string "Abc", expected u32 |
| 258 |
Second: invalid digit found in string |
| 259 |
``` |
| 260 |
|
| 261 |
### Fixed |
| 262 |
|
| 263 |
* Specify the correct minimum serde version as dependency. (#588) |
| 264 |
Thanks to @nox for submitting a PR. |
| 265 |
|
| 266 |
## [2.3.1] - 2023-03-10 |
| 267 |
|
| 268 |
### Fixed |
| 269 |
|
| 270 |
* Undo the changes to the trait bound for `Seq`. (#570, #571) |
| 271 |
The new implementation caused issues with serialization formats that require the sequence length beforehand. |
| 272 |
It also caused problems such as that certain attributes which worked before no longer worked, due to a mismatching number of references. |
| 273 |
|
| 274 |
Thanks to @stefunctional for reporting and for @stephaneyfx for providing a test case. |
| 275 |
|
| 276 |
## [2.3.0] - 2023-03-09 |
| 277 |
|
| 278 |
### Added |
| 279 |
|
| 280 |
* Add `serde_as` compatible versions for the existing duplicate key and value handling. (#534) |
| 281 |
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`. |
| 282 |
* Added a new `KeyValueMap` type using the map key as a struct field. (#341) |
| 283 |
This conversion is useful for maps, where an ID value is the map key, but the ID should become part of a single struct. |
| 284 |
The conversion allows this, by using a special field named `$key$`. |
| 285 |
|
| 286 |
This conversion is possible for structs and maps, using the `$key$` field. |
| 287 |
Tuples, tuple structs, and sequences are supported by turning the first value into the map key. |
| 288 |
|
| 289 |
Each of the `SimpleStruct`s |
| 290 |
|
| 291 |
```rust |
| 292 |
// Somewhere there is a collection: |
| 293 |
// #[serde_as(as = "KeyValueMap<_>")] |
| 294 |
// Vec<SimpleStruct>, |
| 295 |
|
| 296 |
#[derive(Serialize, Deserialize)] |
| 297 |
struct SimpleStruct { |
| 298 |
b: bool, |
| 299 |
// The field named `$key$` will become the map key |
| 300 |
#[serde(rename = "$key$")] |
| 301 |
id: String, |
| 302 |
i: i32, |
| 303 |
} |
| 304 |
``` |
| 305 |
|
| 306 |
will turn into a JSON snippet like this. |
| 307 |
|
| 308 |
```json |
| 309 |
"id-0000": { |
| 310 |
"b": false, |
| 311 |
"i": 123 |
| 312 |
}, |
| 313 |
``` |
| 314 |
|
| 315 |
### Changed |
| 316 |
|
| 317 |
* Relax the trait bounds of `Seq` to allow for more custom types. (#565) |
| 318 |
This extends the support beyond tuples. |
| 319 |
|
| 320 |
### Fixed |
| 321 |
|
| 322 |
* `EnumMap` passes the `human_readable` status of the `Serializer` to more places. |
| 323 |
* Support `alloc` on targets without `target_has_atomic = "ptr"`. (#560) |
| 324 |
Thanks to @vembacher for reporting and fixing the issue. |
| 325 |
|
| 326 |
## [2.2.0] - 2023-01-09 |
| 327 |
|
| 328 |
### Added |
| 329 |
|
| 330 |
* Add new `Map` and `Seq` types for converting between maps and tuple lists. (#527) |
| 331 |
|
| 332 |
The behavior is not new, but already present using `BTreeMap`/`HashMap` or `Vec`. |
| 333 |
However, the new types `Map` and `Seq` are also available on `no_std`, even without the `alloc` feature. |
| 334 |
|
| 335 |
### Changed |
| 336 |
|
| 337 |
* Pin the `serde_with_macros` dependency to the same version as the main crate. |
| 338 |
This simplifies publishing and ensures a compatible version is always picked. |
| 339 |
|
| 340 |
### Fixed |
| 341 |
|
| 342 |
* `serde_with::apply` had an issue matching types when invisible token groups where in use (#538) |
| 343 |
The token groups can stem from macro_rules expansion, but should be treated mostly transparent. |
| 344 |
The old code required a group to match a group, while now groups are silently removed when checking for type patterns. |
| 345 |
|
| 346 |
## [2.1.0] - 2022-11-16 |
| 347 |
|
| 348 |
### Added |
| 349 |
|
| 350 |
* Add new `apply` attribute to simplify repetitive attributes over many fields. |
| 351 |
Multiple rules and multiple attributes can be provided each. |
| 352 |
|
| 353 |
```rust |
| 354 |
#[serde_with::apply( |
| 355 |
Option => #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")], |
| 356 |
Option<bool> => #[serde(rename = "bool")], |
| 357 |
)] |
| 358 |
#[derive(serde::Serialize)] |
| 359 |
struct Data { |
| 360 |
a: Option<String>, |
| 361 |
b: Option<u64>, |
| 362 |
c: Option<String>, |
| 363 |
d: Option<bool>, |
| 364 |
} |
| 365 |
``` |
| 366 |
|
| 367 |
The `apply` attribute will expand into this, applying the attributes to the matching fields: |
| 368 |
|
| 369 |
```rust |
| 370 |
#[derive(serde::Serialize)] |
| 371 |
struct Data { |
| 372 |
#[serde(default)] |
| 373 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 374 |
a: Option<String>, |
| 375 |
#[serde(default)] |
| 376 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 377 |
b: Option<u64>, |
| 378 |
#[serde(default)] |
| 379 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 380 |
c: Option<String>, |
| 381 |
#[serde(default)] |
| 382 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 383 |
#[serde(rename = "bool")] |
| 384 |
d: Option<bool>, |
| 385 |
} |
| 386 |
``` |
| 387 |
|
| 388 |
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<String>`, `Option<bool>`, or `Option<T>`. |
| 389 |
|
| 390 |
### Fixed |
| 391 |
|
| 392 |
* The derive macros `SerializeDisplay` and `DeserializeFromStr` now take better care not to use conflicting names for generic values. (#526) |
| 393 |
All used generics now start with `__` to make conflicts with manually written code unlikely. |
| 394 |
|
| 395 |
Thanks to @Elrendio for submitting a PR fixing the issue. |
| 396 |
|
| 397 |
## [2.0.1] - 2022-09-09 |
| 398 |
|
| 399 |
### Added |
| 400 |
|
| 401 |
* `time` added support for the well-known `Iso8601` format. |
| 402 |
This extends the existing support of `Rfc2822` and `Rfc3339`. |
| 403 |
|
| 404 |
### Changed |
| 405 |
|
| 406 |
* Warn if `serde_as` is used on an enum variant. |
| 407 |
Attributes on enum variants were never supported. |
| 408 |
But `#[serde(with = "...")]` can be added on variants, such that some confusion can occur when migration ([#499](https://github.com/jonasbb/serde_with/issues/499)). |
| 409 |
|
| 410 |
### Note |
| 411 |
|
| 412 |
A cargo bug ([cargo#10801](https://github.com/rust-lang/cargo/issues/10801)) means that upgrading from v1 to v2 may add unnecessary crates to the `Cargo.lock` file. |
| 413 |
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. |
| 414 |
However, tools consuming `Cargo.lock` or `cargo metadata` might give wrong results. |
| 415 |
|
| 416 |
## [2.0.0] - 2022-07-17 |
| 417 |
|
| 418 |
### Added |
| 419 |
|
| 420 |
* Make `JsonString<T>` smarter by allowing nesting `serde_as` definitions. |
| 421 |
This allows applying custom serialization logic before the value gets converted into a JSON string. |
| 422 |
|
| 423 |
```rust |
| 424 |
// Rust |
| 425 |
#[serde_as(as = "JsonString<Vec<(JsonString, _)>>")] |
| 426 |
value: BTreeMap<[u8; 2], u32>, |
| 427 |
|
| 428 |
// JSON |
| 429 |
{"value":"[[\"[1,2]\",3],[\"[4,5]\",6]]"} |
| 430 |
``` |
| 431 |
|
| 432 |
### Changed |
| 433 |
|
| 434 |
* Make `#[serde_as]` behave more intuitive on `Option<T>` fields. |
| 435 |
|
| 436 |
The `#[serde_as]` macro now detects if a `#[serde_as(as = "Option<S>")]` is used on a field of type `Option<T>` and applies `#[serde(default)]` to the field. |
| 437 |
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417). |
| 438 |
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired. |
| 439 |
|
| 440 |
The `Option` field and transformation are detected by directly matching on the type name. |
| 441 |
These variants are detected as `Option`. |
| 442 |
* `Option` |
| 443 |
* `std::option::Option`, with or without leading `::` |
| 444 |
* `core::option::Option`, with or without leading `::` |
| 445 |
|
| 446 |
If an existing `default` attribute is detected, the attribute is not applied again. |
| 447 |
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`. |
| 448 |
* `NoneAsEmptyString` and `string_empty_as_none` use a different serialization bound (#388). |
| 449 |
|
| 450 |
Both types used `AsRef<str>` as the serialization bound. |
| 451 |
This is limiting for non-string types like `Option<i32>`. |
| 452 |
The deserialization often was already more flexible, due to the `FromStr` bound. |
| 453 |
|
| 454 |
For most std types this should have little impact, as the types implementing `AsRef<str>` mostly implement `Display`, too, such as `String`, `Cow<str>`, or `Rc<str>`. |
| 455 |
* Bump MSRV to 1.60. This is required for the optional dependency feature syntax in cargo. |
| 456 |
|
| 457 |
### Removed |
| 458 |
|
| 459 |
* Remove old module-based conversions. |
| 460 |
|
| 461 |
The newer `serde_as` based conversions are preferred. |
| 462 |
|
| 463 |
* `seq_display_fromstr`: Use `DisplayFromStr` in combination with your container type: |
| 464 |
|
| 465 |
```rust |
| 466 |
#[serde_as(as = "BTreeSet<DisplayFromStr>")] |
| 467 |
addresses: BTreeSet<Ipv4Addr>, |
| 468 |
#[serde_as(as = "Vec<DisplayFromStr>")] |
| 469 |
bools: Vec<bool>, |
| 470 |
``` |
| 471 |
|
| 472 |
* `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples: |
| 473 |
|
| 474 |
```rust |
| 475 |
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work |
| 476 |
s: Vec<(i32, String)>, |
| 477 |
``` |
| 478 |
|
| 479 |
* `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`. |
| 480 |
* `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`. |
| 481 |
* `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`. |
| 482 |
* `default_on_error` can be replaced with `#[serde_as(as = "DefaultOnError")]`. |
| 483 |
* `default_on_null` can be replaced with `#[serde_as(as = "DefaultOnNull")]`. |
| 484 |
* `string_empty_as_none` can be replaced with `#[serde_as(as = "NoneAsEmptyString")]`. |
| 485 |
* `StringWithSeparator` can now only be used in `serde_as`. |
| 486 |
The definition of the `Separator` trait and its implementations have been moved to the `formats` module. |
| 487 |
* `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`. |
| 488 |
|
| 489 |
* Remove previously deprecated modules. |
| 490 |
|
| 491 |
* `sets_first_value_wins` |
| 492 |
* `btreemap_as_tuple_list` and `hashmap_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`. |
| 493 |
|
| 494 |
### Note |
| 495 |
|
| 496 |
A cargo bug ([cargo#10801](https://github.com/rust-lang/cargo/issues/10801)) means that upgrading from v1 to v2 may add unnecessary crates to the `Cargo.lock` file. |
| 497 |
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. |
| 498 |
|
| 499 |
## [2.0.0-rc.0] - 2022-06-29 |
| 500 |
|
| 501 |
### Changed |
| 502 |
|
| 503 |
* Make `#[serde_as]` behave more intuitive on `Option<T>` fields. |
| 504 |
|
| 505 |
The `#[serde_as]` macro now detects if a `#[serde_as(as = "Option<S>")]` is used on a field of type `Option<T>` and applies `#[serde(default)]` to the field. |
| 506 |
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417). |
| 507 |
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired. |
| 508 |
|
| 509 |
The `Option` field and transformation are detected by directly matching on the type name. |
| 510 |
These variants are detected as `Option`. |
| 511 |
* `Option` |
| 512 |
* `std::option::Option`, with or without leading `::` |
| 513 |
* `core::option::Option`, with or without leading `::` |
| 514 |
|
| 515 |
If an existing `default` attribute is detected, the attribute is not applied again. |
| 516 |
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`. |
| 517 |
* `NoneAsEmptyString` and `string_empty_as_none` use a different serialization bound (#388). |
| 518 |
|
| 519 |
Both types used `AsRef<str>` as the serialization bound. |
| 520 |
This is limiting for non-string types like `Option<i32>`. |
| 521 |
The deserialization often was already more flexible, due to the `FromStr` bound. |
| 522 |
|
| 523 |
For most std types this should have little impact, as the types implementing `AsRef<str>` mostly implement `Display`, too, such as `String`, `Cow<str>`, or `Rc<str>`. |
| 524 |
* Bump MSRV to 1.60. This is required for the optional dependency feature syntax in cargo. |
| 525 |
|
| 526 |
### Removed |
| 527 |
|
| 528 |
* Remove old module-based conversions. |
| 529 |
|
| 530 |
The newer `serde_as` based conversions are preferred. |
| 531 |
|
| 532 |
* `seq_display_fromstr`: Use `DisplayFromStr` in combination with your container type: |
| 533 |
|
| 534 |
```rust |
| 535 |
#[serde_as(as = "BTreeSet<DisplayFromStr>")] |
| 536 |
addresses: BTreeSet<Ipv4Addr>, |
| 537 |
#[serde_as(as = "Vec<DisplayFromStr>")] |
| 538 |
bools: Vec<bool>, |
| 539 |
``` |
| 540 |
|
| 541 |
* `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples: |
| 542 |
|
| 543 |
```rust |
| 544 |
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work |
| 545 |
s: Vec<(i32, String)>, |
| 546 |
``` |
| 547 |
|
| 548 |
* `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`. |
| 549 |
* `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`. |
| 550 |
* `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`. |
| 551 |
* `default_on_error` can be replaced with `#[serde_as(as = "DefaultOnError")]`. |
| 552 |
* `default_on_null` can be replaced with `#[serde_as(as = "DefaultOnNull")]`. |
| 553 |
* `string_empty_as_none` can be replaced with `#[serde_as(as = "NoneAsEmptyString")]`. |
| 554 |
* `StringWithSeparator` can now only be used in `serde_as`. |
| 555 |
The definition of the `Separator` trait and its implementations have been moved to the `formats` module. |
| 556 |
* `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`. |
| 557 |
|
| 558 |
* Remove previously deprecated modules. |
| 559 |
|
| 560 |
* `sets_first_value_wins` |
| 561 |
* `btreemap_as_tuple_list` and `hashmap_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`. |
| 562 |
|
| 563 |
## [1.14.0] - 2022-05-29 |
| 564 |
|
| 565 |
### Added |
| 566 |
|
| 567 |
* Add support for `time` crate v0.3 #450 |
| 568 |
|
| 569 |
`time::Duration` can now be serialized with the `DurationSeconds` and related converters. |
| 570 |
|
| 571 |
```rust |
| 572 |
// Rust |
| 573 |
#[serde_as(as = "serde_with::DurationSeconds<u64>")] |
| 574 |
value: Duration, |
| 575 |
|
| 576 |
// JSON |
| 577 |
"value": 86400, |
| 578 |
``` |
| 579 |
|
| 580 |
`time::OffsetDateTime` and `time::PrimitiveDateTime` can now be serialized with the `TimestampSeconds` and related converters. |
| 581 |
|
| 582 |
```rust |
| 583 |
// Rust |
| 584 |
#[serde_as(as = "serde_with::TimestampMicroSecondsWithFrac<String>")] |
| 585 |
value: time::PrimitiveDateTime, |
| 586 |
|
| 587 |
// JSON |
| 588 |
"value": "1000000", |
| 589 |
``` |
| 590 |
|
| 591 |
`time::OffsetDateTime` can be serialized in string format in different well-known formats. |
| 592 |
Two formats are supported, `time::format_description::well_known::Rfc2822` and `time::format_description::well_known::Rfc3339`. |
| 593 |
|
| 594 |
```rust |
| 595 |
// Rust |
| 596 |
#[serde_as(as = "time::format_description::well_known::Rfc2822")] |
| 597 |
rfc_2822: OffsetDateTime, |
| 598 |
#[serde_as(as = "Vec<time::format_description::well_known::Rfc3339>")] |
| 599 |
rfc_3339: Vec<OffsetDateTime>, |
| 600 |
|
| 601 |
// JSON |
| 602 |
"rfc_2822": "Fri, 21 Nov 1997 09:55:06 -0600", |
| 603 |
"rfc_3339": ["1997-11-21T09:55:06-06:00"], |
| 604 |
``` |
| 605 |
|
| 606 |
* Deserialize `bool` from integers #456 462 |
| 607 |
|
| 608 |
Deserialize an integer and convert it into a `bool`. |
| 609 |
`BoolFromInt<Strict>` (default) deserializes 0 to `false` and `1` to `true`, other numbers are errors. |
| 610 |
`BoolFromInt<Flexible>` deserializes any non-zero as `true`. |
| 611 |
Serialization only emits 0/1. |
| 612 |
|
| 613 |
```rust |
| 614 |
// Rust |
| 615 |
#[serde_as(as = "BoolFromInt")] // BoolFromInt<Strict> |
| 616 |
b: bool, |
| 617 |
|
| 618 |
// JSON |
| 619 |
"b": 1, |
| 620 |
``` |
| 621 |
|
| 622 |
### Changed |
| 623 |
|
| 624 |
* Bump MSRV to 1.53, since the new dependency `time` requires that version. |
| 625 |
|
| 626 |
### Fixed |
| 627 |
|
| 628 |
* Make the documentation clearer by stating that the `#[serde_as]` and `#[skip_serializing_none]` attributes must always be places before `#[derive]`. |
| 629 |
|
| 630 |
## [1.13.0] - 2022-04-23 |
| 631 |
|
| 632 |
### Added |
| 633 |
|
| 634 |
* Added support for `indexmap::IndexMap` and `indexmap::IndexSet` types. #431, #436 |
| 635 |
|
| 636 |
Both types are now compatible with these functions: `maps_duplicate_key_is_error`, `maps_first_key_wins`, `sets_duplicate_value_is_error`, `sets_last_value_wins`. |
| 637 |
`serde_as` integration is provided by implementing both `SerializeAs` and `DeserializeAs` for both types. |
| 638 |
`IndexMap`s can also be serialized as a list of types via the `serde_as(as = "Vec<(_, _)>")` annotation. |
| 639 |
|
| 640 |
All implementations are gated behind the `indexmap` feature. |
| 641 |
|
| 642 |
Thanks to @jgrund for providing parts of the implementation. |
| 643 |
|
| 644 |
## [1.12.1] - 2022-04-07 |
| 645 |
|
| 646 |
### Fixed |
| 647 |
|
| 648 |
* Depend on a newer `serde_with_macros` version to pull in some fixes. |
| 649 |
* Account for generics when deriving implementations with `SerializeDisplay` and `DeserializeFromStr` #413 |
| 650 |
* Provide better error messages when parsing types fails #423 |
| 651 |
|
| 652 |
## [1.12.0] - 2022-02-07 |
| 653 |
|
| 654 |
### Added |
| 655 |
|
| 656 |
* Deserialize a `Vec` and skip all elements failing to deserialize #383 |
| 657 |
|
| 658 |
`VecSkipError` acts like a `Vec`, but elements which fail to deserialize, like the `"Yellow"` are ignored. |
| 659 |
|
| 660 |
```rust |
| 661 |
#[derive(serde::Deserialize)] |
| 662 |
enum Color { |
| 663 |
Red, |
| 664 |
Green, |
| 665 |
Blue, |
| 666 |
} |
| 667 |
// JSON |
| 668 |
"colors": ["Blue", "Yellow", "Green"], |
| 669 |
// Rust |
| 670 |
#[serde_as(as = "VecSkipError<_>")] |
| 671 |
colors: Vec<Color>, |
| 672 |
// => vec![Blue, Green] |
| 673 |
``` |
| 674 |
|
| 675 |
Thanks to @hdhoang for creating the PR. |
| 676 |
|
| 677 |
* Transform between maps and `Vec<Enum>` #375 |
| 678 |
|
| 679 |
The new `EnumMap` type converts `Vec` of enums into a single map. |
| 680 |
The key is the enum variant name, and the value is the variant value. |
| 681 |
|
| 682 |
```rust |
| 683 |
// Rust |
| 684 |
VecEnumValues(vec![ |
| 685 |
EnumValue::Int(123), |
| 686 |
EnumValue::String("Foo".to_string()), |
| 687 |
EnumValue::Unit, |
| 688 |
EnumValue::Tuple(1, "Bar".to_string()), |
| 689 |
EnumValue::Struct { |
| 690 |
a: 666, |
| 691 |
b: "Baz".to_string(), |
| 692 |
}, |
| 693 |
] |
| 694 |
|
| 695 |
// JSON |
| 696 |
{ |
| 697 |
"Int": 123, |
| 698 |
"String": "Foo", |
| 699 |
"Unit": null, |
| 700 |
"Tuple": [ |
| 701 |
1, |
| 702 |
"Bar", |
| 703 |
], |
| 704 |
"Struct": { |
| 705 |
"a": 666, |
| 706 |
"b": "Baz", |
| 707 |
} |
| 708 |
} |
| 709 |
``` |
| 710 |
|
| 711 |
### Changed |
| 712 |
|
| 713 |
* The `Timestamp*Seconds` and `Timestamp*SecondsWithFrac` types can now be used with `chrono::NaiveDateTime`. #389 |
| 714 |
|
| 715 |
## [1.11.0] - 2021-10-18 |
| 716 |
|
| 717 |
### Added |
| 718 |
|
| 719 |
* Serialize bytes as base64 encoded strings. |
| 720 |
The character set and padding behavior can be configured. |
| 721 |
|
| 722 |
```rust |
| 723 |
// Rust |
| 724 |
#[serde_as(as = "serde_with::base64::Base64")] |
| 725 |
value: Vec<u8>, |
| 726 |
#[serde_as(as = "Base64<Bcrypt, Unpadded>")] |
| 727 |
bcrypt_unpadded: Vec<u8>, |
| 728 |
|
| 729 |
// JSON |
| 730 |
"value": "SGVsbG8gV29ybGQ=", |
| 731 |
"bcrypt_unpadded": "QETqZE6eT07wZEO", |
| 732 |
``` |
| 733 |
|
| 734 |
* The minimal supported Rust version (MSRV) is now specified in the `Cargo.toml` via the `rust-version` field. The field is supported in Rust 1.56 and has no effect on versions before. |
| 735 |
|
| 736 |
More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field |
| 737 |
|
| 738 |
### Fixed |
| 739 |
|
| 740 |
* Fixed RUSTSEC-2020-0071 in the `time` v0.1 dependency, but changing the feature flags of the `chrono` dependency. This should not change anything. Crates requiring the `oldtime` feature of `chrono` can enable it separately. |
| 741 |
* Allow `HashSet`s with custom hashers to be deserialized when used in combination with `serde_as`. #408 |
| 742 |
|
| 743 |
## [1.10.0] - 2021-09-04 |
| 744 |
|
| 745 |
### Added |
| 746 |
|
| 747 |
* Add `BorrowCow` which instructs serde to borrow data during deserialization of `Cow<'_, str>`, `Cow<'_, [u8]>`, or `Cow<'_, [u8; N]>`. (#347) |
| 748 |
The implementation is for [serde#2072](https://github.com/serde-rs/serde/pull/2072#pullrequestreview-735511713) and [serde#2016](https://github.com/serde-rs/serde/issues/2016), about `#[serde(borrow)]` not working for `Option<Cow<'a, str>>`. |
| 749 |
|
| 750 |
```rust |
| 751 |
#[serde_as] |
| 752 |
#[derive(Deserialize, Serialize)] |
| 753 |
struct Data<'a> { |
| 754 |
#[serde_as(as = "Option<[BorrowCow; 1]>")] |
| 755 |
nested: Option<[Cow<'a, str>; 1]>, |
| 756 |
} |
| 757 |
``` |
| 758 |
|
| 759 |
The `#[serde(borrow)]` annotation is automatically added by the `#[serde_as]` attribute. |
| 760 |
|
| 761 |
### Changed |
| 762 |
|
| 763 |
* Bump MSRV to 1.46, since the dev-dependency `bitflags` requires that version now. |
| 764 |
* `flattened_maybe!` no longer requires the `serde_with` crate to be available with a specific name. |
| 765 |
This allows renaming the crate or using `flattened_maybe!` through a re-export without any complications. |
| 766 |
|
| 767 |
## [1.9.4] - 2021-06-18 |
| 768 |
|
| 769 |
### Fixed |
| 770 |
|
| 771 |
* `with_prefix!` now supports an optional visibility modifier. (#327, #328) |
| 772 |
If not specified `pub(self)` is assumed. |
| 773 |
|
| 774 |
```rust |
| 775 |
with_prefix!(prefix_active "active_"); // => mod {...} |
| 776 |
with_prefix!(pub prefix_active "active_"); // => pub mod {...} |
| 777 |
with_prefix!(pub(crate) prefix_active "active_"); // => pub(crate) mod {...} |
| 778 |
with_prefix!(pub(in other_mod) prefix_active "active_"); // => pub(in other_mod) mod {...} |
| 779 |
``` |
| 780 |
|
| 781 |
Thanks to @elpiel for raising and fixing the issue. |
| 782 |
|
| 783 |
## [1.9.3] - 2021-06-14 |
| 784 |
|
| 785 |
### Added |
| 786 |
|
| 787 |
* The `Bytes` type now supports borrowed and Cow arrays of fixed size (requires Rust 1.51+) |
| 788 |
|
| 789 |
```rust |
| 790 |
#[serde_as(as = "Bytes")] |
| 791 |
#[serde(borrow)] |
| 792 |
borrowed_array: &'a [u8; 15], |
| 793 |
#[serde_as(as = "Bytes")] |
| 794 |
#[serde(borrow)] |
| 795 |
cow_array: Cow<'a, [u8; 15]>, |
| 796 |
``` |
| 797 |
|
| 798 |
Note: For borrowed arrays, the used Deserializer needs to support Serde's 0-copy deserialization. |
| 799 |
|
| 800 |
## [1.9.2] - 2021-06-07 |
| 801 |
|
| 802 |
### Fixed |
| 803 |
|
| 804 |
* Suppress clippy warnings, which can occur while using `serde_conv` (#320) |
| 805 |
Thanks to @mkroening for reporting and fixing the issue. |
| 806 |
|
| 807 |
## [1.9.1] - 2021-05-15 |
| 808 |
|
| 809 |
### Changed |
| 810 |
|
| 811 |
* `NoneAsEmptyString`: Deserialize using `FromStr` instead of using `for<'a> From<&'a str>` (#316) |
| 812 |
This will *not* change any behavior when applied to a field of type `Option<String>` as used in the documentation. |
| 813 |
Thanks to @mkroening for finding and fixing the issue. |
| 814 |
|
| 815 |
## [1.9.0] - 2021-05-09 |
| 816 |
|
| 817 |
### Added |
| 818 |
|
| 819 |
* Added `FromInto` and `TryFromInto` adapters, which enable serialization by converting into a proxy type. |
| 820 |
|
| 821 |
```rust |
| 822 |
// Rust |
| 823 |
#[serde_as(as = "FromInto<(u8, u8, u8)>")] |
| 824 |
value: Rgb, |
| 825 |
|
| 826 |
impl From<(u8, u8, u8)> for Rgb { ... } |
| 827 |
impl From<Rgb> for (u8, u8, u8) { ... } |
| 828 |
|
| 829 |
// JSON |
| 830 |
"value": [128, 64, 32], |
| 831 |
``` |
| 832 |
|
| 833 |
* New `serde_conv!` macro to create conversion types with reduced boilerplate. |
| 834 |
The generated types can be used with `#[serde_as]` or serde's with-attribute. |
| 835 |
|
| 836 |
```rust |
| 837 |
serde_with::serde_conv!( |
| 838 |
RgbAsArray, |
| 839 |
Rgb, |
| 840 |
|rgb: &Rgb| [rgb.red, rgb.green, rgb.blue], |
| 841 |
|value: [u8; 3]| -> Result<_, std::convert::Infallible> { |
| 842 |
Ok(Rgb { |
| 843 |
red: value[0], |
| 844 |
green: value[1], |
| 845 |
blue: value[2], |
| 846 |
}) |
| 847 |
} |
| 848 |
); |
| 849 |
``` |
| 850 |
|
| 851 |
## [1.8.1] - 2021-04-19 |
| 852 |
|
| 853 |
### Added |
| 854 |
|
| 855 |
* The `hex::Hex` type also works for u8-arrays on Rust 1.48. |
| 856 |
Thanks to @TheAlgorythm for raising and fixing the issue. |
| 857 |
|
| 858 |
## [1.8.0] - 2021-03-30 |
| 859 |
|
| 860 |
### Added |
| 861 |
|
| 862 |
* Added `PickFirst` adapter for `serde_as`. [#291] |
| 863 |
It allows deserializing from multiple different forms. |
| 864 |
Deserializing a number from either a number or string can be implemented like: |
| 865 |
|
| 866 |
```rust |
| 867 |
#[serde_as(as = "PickFirst<(_, DisplayFromStr)>")] |
| 868 |
value: u32, |
| 869 |
``` |
| 870 |
|
| 871 |
* Implement `SerializeAs`/`DeserializeAs` for more wrapper types. [#288], [#293] |
| 872 |
This now supports: |
| 873 |
* `Arc`, `sync::Weak` |
| 874 |
* `Rc`, `rc::Weak` |
| 875 |
* `Cell`, `RefCell` |
| 876 |
* `Mutex`, `RwLock` |
| 877 |
* `Result` |
| 878 |
|
| 879 |
[#288]: https://github.com/jonasbb/serde_with/issues/288 |
| 880 |
[#291]: https://github.com/jonasbb/serde_with/issues/291 |
| 881 |
[#293]: https://github.com/jonasbb/serde_with/issues/293 |
| 882 |
|
| 883 |
### Changed |
| 884 |
|
| 885 |
* Add a new `serde_with::rust::map_as_tuple_list` module as a replacement for `serde_with::rust::btreemap_as_tuple_list` and `serde_with::rust::hashmap_as_tuple_list`. |
| 886 |
The new module uses `IntoIterator` and `FromIterator` as trait bound making it usable in more situations. |
| 887 |
The old names continue to exist but are marked as deprecated. |
| 888 |
|
| 889 |
### Deprecated |
| 890 |
|
| 891 |
* Deprecated the module names `serde_with::rust::btreemap_as_tuple_list` and `serde_with::rust::hashmap_as_tuple_list`. |
| 892 |
You can use `serde_with::rust::map_as_tuple_list` as a replacement. |
| 893 |
|
| 894 |
### Fixed |
| 895 |
|
| 896 |
* Implement `Timestamp*Seconds` and `Duration*Seconds` also for chrono types. |
| 897 |
This closes [#194]. This was incompletely implemented in [#199]. |
| 898 |
|
| 899 |
[#194]: https://github.com/jonasbb/serde_with/issues/194 |
| 900 |
[#199]: https://github.com/jonasbb/serde_with/issues/199 |
| 901 |
|
| 902 |
## [1.7.0] - 2021-03-24 |
| 903 |
|
| 904 |
### Added |
| 905 |
|
| 906 |
* Add support for arrays of arbitrary size. ([#272]) |
| 907 |
This feature requires Rust 1.51+. |
| 908 |
|
| 909 |
```rust |
| 910 |
// Rust |
| 911 |
#[serde_as(as = "[[_; 64]; 33]")] |
| 912 |
value: [[u8; 64]; 33], |
| 913 |
|
| 914 |
// JSON |
| 915 |
"value": [[0,0,0,0,0,...], [0,0,0,...], ...], |
| 916 |
``` |
| 917 |
|
| 918 |
Mapping of arrays was available before, but limited to arrays of length 32. |
| 919 |
All conversion methods are available for the array elements. |
| 920 |
|
| 921 |
This is similar to the existing [`serde-big-array`] crate with three important improvements: |
| 922 |
|
| 923 |
1. Support for the `serde_as` annotation. |
| 924 |
2. Supports non-copy elements (see [serde-big-array#6][serde-big-array-copy]). |
| 925 |
3. Supports arbitrary nestings of arrays (see [serde-big-array#7][serde-big-array-nested]). |
| 926 |
|
| 927 |
[#272]: https://github.com/jonasbb/serde_with/pull/272 |
| 928 |
[`serde-big-array`]: https://crates.io/crates/serde-big-array |
| 929 |
[serde-big-array-copy]: https://github.com/est31/serde-big-array/issues/6 |
| 930 |
[serde-big-array-nested]: https://github.com/est31/serde-big-array/issues/7 |
| 931 |
|
| 932 |
* Arrays with tuple elements can now be deserialized from a map. ([#272]) |
| 933 |
This feature requires Rust 1.51+. |
| 934 |
|
| 935 |
```rust |
| 936 |
// Rust |
| 937 |
#[serde_as(as = "BTreeMap<_, _>")] |
| 938 |
value: [(String, u16); 3], |
| 939 |
|
| 940 |
// JSON |
| 941 |
"value": { |
| 942 |
"a": 1, |
| 943 |
"b": 2, |
| 944 |
"c": 3 |
| 945 |
}, |
| 946 |
``` |
| 947 |
|
| 948 |
* The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the `serde_as` system. ([#277]) |
| 949 |
|
| 950 |
```rust |
| 951 |
#[serde_as(as = "Bytes")] |
| 952 |
value: Vec<u8>, |
| 953 |
``` |
| 954 |
|
| 955 |
Compared to `serde_bytes` these improvements are available |
| 956 |
|
| 957 |
1. Integration with the `serde_as` annotation (see [serde-bytes#14][serde-bytes-complex]). |
| 958 |
2. Implementation for arrays of arbitrary size (Rust 1.51+) (see [serde-bytes#26][serde-bytes-arrays]). |
| 959 |
|
| 960 |
[#277]: https://github.com/jonasbb/serde_with/pull/277 |
| 961 |
[serde-bytes-complex]: https://github.com/serde-rs/bytes/issues/14 |
| 962 |
[serde-bytes-arrays]: https://github.com/serde-rs/bytes/issues/26 |
| 963 |
|
| 964 |
* The `OneOrMany` type allows deserializing a `Vec` from either a single element or a sequence. ([#281]) |
| 965 |
|
| 966 |
```rust |
| 967 |
#[serde_as(as = "OneOrMany<_>")] |
| 968 |
cities: Vec<String>, |
| 969 |
``` |
| 970 |
|
| 971 |
This allows deserializing from either `cities: "Berlin"` or `cities: ["Berlin", "Paris"]`. |
| 972 |
The serialization can be configured to always emit a list with `PreferMany` or emit a single element with `PreferOne`. |
| 973 |
|
| 974 |
[#281]: https://github.com/jonasbb/serde_with/pull/281 |
| 975 |
|
| 976 |
## [1.6.4] - 2021-02-16 |
| 977 |
|
| 978 |
### Fixed |
| 979 |
|
| 980 |
* Fix compiling when having a struct field without the `serde_as` annotation by updating `serde_with_macros`. |
| 981 |
This broke in 1.4.0 of `serde_with_macros`. [#267](https://github.com/jonasbb/serde_with/issues/267) |
| 982 |
|
| 983 |
## [1.6.3] - 2021-02-15 |
| 984 |
|
| 985 |
### Changed |
| 986 |
|
| 987 |
* Bump macro crate dependency (`serde_with_macros`) to 1.4.0 to pull in those improvements. |
| 988 |
|
| 989 |
## [1.6.2] - 2021-01-30 |
| 990 |
|
| 991 |
### Added |
| 992 |
|
| 993 |
* New function `serde_with::rust::deserialize_ignore_any`. |
| 994 |
This function allows deserializing any data and returns the default value of the type. |
| 995 |
This can be used in conjunction with `#[serde(other)]` to allow deserialization of unknown data carrying enum variants. |
| 996 |
|
| 997 |
Thanks to @lovasoa for suggesting and implementing it. |
| 998 |
|
| 999 |
## [1.6.1] - 2021-01-24 |
| 1000 |
|
| 1001 |
### Added |
| 1002 |
|
| 1003 |
* Add new types similar to `DurationSeconds` and `TimestampSeconds` but for base units of milliseconds, microseconds, and nanoseconds. |
| 1004 |
The `*WithFrac` variants also exist. |
| 1005 |
* Add `SerializeAs` implementation for references. |
| 1006 |
|
| 1007 |
### Changed |
| 1008 |
|
| 1009 |
* Release `Sized` trait bound from `As`, `Same`, `SerializeAs`, and `SerializeAsWrap`. |
| 1010 |
Only the `serialize` part is relaxed. |
| 1011 |
|
| 1012 |
## [1.6.0] - 2020-11-22 |
| 1013 |
|
| 1014 |
### Added |
| 1015 |
|
| 1016 |
* Add `DefaultOnNull` as the equivalent for `rust::default_on_null` but for the `serde_as` system. |
| 1017 |
* Support specifying a path to the `serde_with` crate for the `serde_as` and derive macros. |
| 1018 |
This is useful when using crate renaming in Cargo.toml or while re-exporting the macros. |
| 1019 |
|
| 1020 |
Many thanks to @tobz1000 for raising the issue and contributing fixes. |
| 1021 |
|
| 1022 |
### Changed |
| 1023 |
|
| 1024 |
* Bump minimum supported rust version to 1.40.0 |
| 1025 |
|
| 1026 |
## [1.5.1] - 2020-10-07 |
| 1027 |
|
| 1028 |
### Fixed |
| 1029 |
|
| 1030 |
* Depend on serde with the `derive` feature enabled. |
| 1031 |
The `derive` feature is required to deserialize untagged enums which are used in the `DefaultOnError` helpers. |
| 1032 |
This fixes compilation of `serde_with` in scenarios where no other crate enables the `derive` feature. |
| 1033 |
|
| 1034 |
## [1.5.0] - 2020-10-01 |
| 1035 |
|
| 1036 |
### Added |
| 1037 |
|
| 1038 |
* The largest addition to this release is the addition of the `serde_as` de/serialization scheme. |
| 1039 |
Its goal is to be a more flexible replacement to serde's `with` annotation, by being more composable than before. |
| 1040 |
No longer is it a problem to add a custom de/serialization adapter is the type is within an `Option` or a `Vec`. |
| 1041 |
|
| 1042 |
Thanks to `@markazmierczak` for the design of the trait without whom this wouldn't be possible. |
| 1043 |
|
| 1044 |
More details about this new scheme can be found in the also new [user guide](https://docs.rs/serde_with/1.5.0/serde_with/guide/index.html) |
| 1045 |
* This release also features a detailed user guide. |
| 1046 |
The guide focuses more on how to use this crate by providing examples. |
| 1047 |
For example, it includes a section about the available feature flags of this crate and how you can migrate to the shiny new `serde_as` scheme. |
| 1048 |
* The crate now features de/serialization adaptors for the std and `chrono` `Duration` types. #56 #104 |
| 1049 |
* Add a `hex` module, which allows formatting bytes (i.e. `Vec<u8>`) as a hexadecimal string. |
| 1050 |
The formatting supports different arguments how the formatting is happening. |
| 1051 |
* Add two derive macros, `SerializeDisplay` and `DeserializeFromStr`, which implement the `Serialize`/`Deserialize` traits based on `Display` and `FromStr`. |
| 1052 |
This is in addition to the already existing methods like `DisplayFromStr`, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem. |
| 1053 |
|
| 1054 |
This is part of `serde_with_macros` v1.2.0. |
| 1055 |
* Added some `serialize` functions to modules which previously had none. |
| 1056 |
This makes it easier to use the conversion when also deriving `Serialize`. |
| 1057 |
The functions simply pass through to the underlying `Serialize` implementation. |
| 1058 |
This affects `sets_duplicate_value_is_error`, `maps_duplicate_key_is_error`, `maps_first_key_wins`, `default_on_error`, and `default_on_null`. |
| 1059 |
* Added `sets_last_value_wins` as a replacement for `sets_first_value_wins` which is deprecated now. |
| 1060 |
The default behavior of serde is to prefer the first value of a set, so the opposite is taking the last value. |
| 1061 |
* Added `#[serde_as]` compatible conversion methods for serializing durations and timestamps as numbers. |
| 1062 |
The four types `DurationSeconds`, `DurationSecondsWithFrac`, `TimestampSeconds`, `TimestampSecondsWithFrac` provide the serialization conversion with optional sub-second precision. |
| 1063 |
There is support for `std::time::Duration`, `chrono::Duration`, `std::time::SystemTime` and `chrono::DateTime`. |
| 1064 |
Timestamps are serialized as durations since the UNIX epoch. |
| 1065 |
The serialization can be customized. |
| 1066 |
It supports multiple formats, such as `i64`, `f64`, or `String`, and the deserialization can be tweaked if it should be strict or lenient when accepting formats. |
| 1067 |
|
| 1068 |
### Changed |
| 1069 |
|
| 1070 |
* Convert the code to use 2018 edition. |
| 1071 |
* @peterjoel improved the performance of `with_prefix!`. #101 |
| 1072 |
|
| 1073 |
### Fixed |
| 1074 |
|
| 1075 |
* The `with_prefix!` macro, to add a string prefixes during serialization, now also works with unit variant enum types. #115 #116 |
| 1076 |
* The `serde_as` macro now supports serde attributes and no longer panic on unrecognized values in the attribute. |
| 1077 |
This is part of `serde_with_macros` v1.2.0. |
| 1078 |
|
| 1079 |
### Deprecated |
| 1080 |
|
| 1081 |
* Deprecate `sets_first_value_wins`. |
| 1082 |
The default behavior of serde is to take the first value, so this module is not necessary. |
| 1083 |
|
| 1084 |
## [1.5.0-alpha.2] - 2020-08-16 |
| 1085 |
|
| 1086 |
### Added |
| 1087 |
|
| 1088 |
* Add a `hex` module, which allows formatting bytes (i.e. `Vec<u8>`) as a hexadecimal string. |
| 1089 |
The formatting supports different arguments how the formatting is happening. |
| 1090 |
* Add two derive macros, `SerializeDisplay` and `DeserializeFromStr`, which implement the `Serialize`/`Deserialize` traits based on `Display` and `FromStr`. |
| 1091 |
This is in addition to the already existing methods like `DisplayFromStr`, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem. |
| 1092 |
|
| 1093 |
This is part of `serde_with_macros` v1.2.0-alpha.3. |
| 1094 |
|
| 1095 |
### Fixed |
| 1096 |
|
| 1097 |
* The `serde_as` macro now supports serde attributes and no longer panic on unrecognized values in the attribute. |
| 1098 |
This is part of `serde_with_macros` v1.2.0-alpha.2. |
| 1099 |
|
| 1100 |
## [1.5.0-alpha.1] - 2020-06-27 |
| 1101 |
|
| 1102 |
### Added |
| 1103 |
|
| 1104 |
* The largest addition to this release is the addition of the `serde_as` de/serialization scheme. |
| 1105 |
Its goal is to be a more flexible replacement to serde's with annotation, by being more composable than before. |
| 1106 |
No longer is it a problem to add a custom de/serialization adapter is the type is within an `Option` or a `Vec`. |
| 1107 |
|
| 1108 |
Thanks to `@markazmierczak` for the design of the trait without whom this wouldn't be possible. |
| 1109 |
|
| 1110 |
More details about this new scheme can be found in the also new [user guide](https://docs.rs/serde_with/1.5.0-alpha.1/serde_with/guide/index.html) |
| 1111 |
* This release also features a detailed user guide. |
| 1112 |
The guide focuses more on how to use this crate by providing examples. |
| 1113 |
For example, it includes a section about the available feature flags of this crate and how you can migrate to the shiny new `serde_as` scheme. |
| 1114 |
* The crate now features de/serialization adaptors for the std and `chrono`'s `Duration` types. #56 #104 |
| 1115 |
|
| 1116 |
### Changed |
| 1117 |
|
| 1118 |
* Convert the code to use 2018 edition. |
| 1119 |
* @peterjoel improved the performance of `with_prefix!`. #101 |
| 1120 |
|
| 1121 |
### Fixed |
| 1122 |
|
| 1123 |
* The `with_prefix!` macro, to add a string prefixes during serialization, now also works with unit variant enum types. #115 #116 |
| 1124 |
|
| 1125 |
## [1.4.0] - 2020-01-16 |
| 1126 |
|
| 1127 |
### Added |
| 1128 |
|
| 1129 |
* Add a helper to deserialize a `Vec<u8>` from `String` (#35) |
| 1130 |
* Add `default_on_error` helper, which turns errors into `Default`s of the type |
| 1131 |
* Add `default_on_null` helper, which turns `null` values into `Default`s of the type |
| 1132 |
|
| 1133 |
### Changed |
| 1134 |
|
| 1135 |
* Bump minimal Rust version to 1.36.0 |
| 1136 |
* Supports Rust Edition 2018 |
| 1137 |
* version-sync depends on smallvec, which requires 1.36 |
| 1138 |
* Improved CI pipeline by running `cargo audit` and `tarpaulin` in all configurations now. |
| 1139 |
|
| 1140 |
## [1.3.1] - 2019-04-09 |
| 1141 |
|
| 1142 |
### Fixed |
| 1143 |
|
| 1144 |
* Use `serde_with_macros` with proper dependencies specified. |
| 1145 |
|
| 1146 |
## [1.3.0] - 2019-04-02 |
| 1147 |
|
| 1148 |
### Added |
| 1149 |
|
| 1150 |
* Add `skip_serializing_none` attribute, which adds `#[serde(skip_serializing_if = "Option::is_none")]` for each Option in a struct. |
| 1151 |
This is helpful for APIs which have many optional fields. |
| 1152 |
The effect of can be negated by adding `serialize_always` on those fields, which should always be serialized. |
| 1153 |
Existing `skip_serializing_if` will never be modified and those fields keep their behavior. |
| 1154 |
|
| 1155 |
## [1.2.0] - 2019-03-04 |
| 1156 |
|
| 1157 |
### Added |
| 1158 |
|
| 1159 |
* Add macro helper to support deserializing values with nested or flattened syntax #38 |
| 1160 |
* Serialize tuple list as map helper |
| 1161 |
|
| 1162 |
### Changed |
| 1163 |
|
| 1164 |
* Bumped minimal Rust version to 1.30.0 |
| 1165 |
|
| 1166 |
## [1.1.0] - 2019-02-18 |
| 1167 |
|
| 1168 |
### Added |
| 1169 |
|
| 1170 |
* Serialize HashMap/BTreeMap as a list of tuples |
| 1171 |
|
| 1172 |
## [1.0.0] - 2019-01-17 |
| 1173 |
|
| 1174 |
### Added |
| 1175 |
|
| 1176 |
* No changes in this release. |
| 1177 |
* Bumped version number to indicate the stability of the library. |
| 1178 |
|
| 1179 |
## [0.2.5] - 2018-11-29 |
| 1180 |
|
| 1181 |
### Added |
| 1182 |
|
| 1183 |
* Helper which deserializes an empty string as `None` and otherwise uses `FromStr` and `AsRef<str>`. |
| 1184 |
|
| 1185 |
## [0.2.4] - 2018-11-24 |
| 1186 |
|
| 1187 |
### Added |
| 1188 |
|
| 1189 |
* De/Serialize sequences by using `Display` and `FromStr` implementations on each element. Contributed by @katyo |
| 1190 |
|
| 1191 |
## [0.2.3] - 2018-11-08 |
| 1192 |
|
| 1193 |
### Added |
| 1194 |
|
| 1195 |
* Add missing docs and enable deny missing_docs |
| 1196 |
* Add badges to Cargo.toml and crates.io |
| 1197 |
|
| 1198 |
### Changed |
| 1199 |
|
| 1200 |
* Improve Travis configuration |
| 1201 |
* Various clippy improvements |
| 1202 |
|
| 1203 |
## [0.2.2] - 2018-08-05 |
| 1204 |
|
| 1205 |
### Added |
| 1206 |
|
| 1207 |
* `unwrap_or_skip` allows to transparently serialize the inner part of a `Some(T)` |
| 1208 |
* Add deserialization helper for sets and maps, inspired by [comment](https://github.com/serde-rs/serde/issues/553#issuecomment-299711855) |
| 1209 |
* Create an error if duplicate values for a set are detected |
| 1210 |
* Create an error if duplicate keys for a map are detected |
| 1211 |
* Implement a "first value wins" strategy for sets/maps. |
| 1212 |
This is different to serde's default, which implements a "last value wins" strategy. |
| 1213 |
|
| 1214 |
## [0.2.1] - 2018-06-05 |
| 1215 |
|
| 1216 |
### Added |
| 1217 |
|
| 1218 |
* Double Option pattern to differentiate between missing, unset, or existing value |
| 1219 |
* `with_prefix!` macro, which puts a prefix on every struct field |
| 1220 |
|
| 1221 |
## [0.2.0] - 2018-05-31 |
| 1222 |
|
| 1223 |
### Added |
| 1224 |
|
| 1225 |
* Add chrono support: Deserialize timestamps from int, float, and string |
| 1226 |
* Serialization of embedded JSON strings |
| 1227 |
* De/Serialization using `Display` and `FromStr` implementations |
| 1228 |
* String-based collections using `Display` and `FromStr`, allows deserializing "#foo,#bar" |
| 1229 |
|
| 1230 |
## [0.1.0] - 2017-08-17 |
| 1231 |
|
| 1232 |
### Added |
| 1233 |
|
| 1234 |
* Reserve name on crates.io |