| 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 |
No changes. |
| 13 |
|
| 14 |
## [3.11.0] - 2024-10-05 |
| 15 |
|
| 16 |
No changes. |
| 17 |
|
| 18 |
## [3.10.0] - 2024-10-01 |
| 19 |
|
| 20 |
### Fixed |
| 21 |
|
| 22 |
* Proper handling of `cfg_attr` in the `serde_as` macro by @sivizius (#782) |
| 23 |
|
| 24 |
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. |
| 25 |
|
| 26 |
## [3.9.0] - 2024-07-14 |
| 27 |
|
| 28 |
No changes. |
| 29 |
|
| 30 |
## [3.8.3] - 2024-07-03 |
| 31 |
|
| 32 |
No changes. |
| 33 |
|
| 34 |
## [3.8.2] - 2024-06-30 |
| 35 |
|
| 36 |
No changes. |
| 37 |
|
| 38 |
## [3.8.1] - 2024-04-28 |
| 39 |
|
| 40 |
No changes. |
| 41 |
|
| 42 |
## [3.8.0] - 2024-04-24 |
| 43 |
|
| 44 |
No changes. |
| 45 |
|
| 46 |
## [3.7.0] - 2024-03-11 |
| 47 |
|
| 48 |
### Fixed |
| 49 |
|
| 50 |
* Detect conflicting `schema_with` attributes on fields with `schemars` annotations by @swlynch99 (#715) |
| 51 |
This extends the existing avoidance mechanism to a new variant fixing #712. |
| 52 |
|
| 53 |
## [3.6.1] - 2024-02-08 |
| 54 |
|
| 55 |
No changes. |
| 56 |
|
| 57 |
## [3.6.0] - 2024-01-30 |
| 58 |
|
| 59 |
No changes. |
| 60 |
|
| 61 |
## [3.5.1] - 2024-01-23 |
| 62 |
|
| 63 |
### Fixed |
| 64 |
|
| 65 |
* The `serde_as` macro now better detects existing `schemars` attributes on fields and incorporates them (#682) |
| 66 |
This avoids errors on existing `#[schemars(with = ...)]` annotations. |
| 67 |
|
| 68 |
## [3.5.0] - 2024-01-20 |
| 69 |
|
| 70 |
### Added |
| 71 |
|
| 72 |
* Support for `schemars` integration added by @swlynch99 (#666) |
| 73 |
The `serde_as` macro can now detect `schemars` usage and emits matching annotations for all fields with `serde_as` attribute. |
| 74 |
|
| 75 |
## [3.4.0] - 2023-10-17 |
| 76 |
|
| 77 |
No changes. |
| 78 |
|
| 79 |
## [3.3.0] - 2023-08-19 |
| 80 |
|
| 81 |
No changes. |
| 82 |
|
| 83 |
## [3.2.0] - 2023-08-04 |
| 84 |
|
| 85 |
No changes. |
| 86 |
|
| 87 |
## [3.1.0] - 2023-07-17 |
| 88 |
|
| 89 |
No changes. |
| 90 |
|
| 91 |
## [3.0.0] - 2023-05-01 |
| 92 |
|
| 93 |
No changes. |
| 94 |
|
| 95 |
## [2.3.3] - 2023-04-27 |
| 96 |
|
| 97 |
### Changed |
| 98 |
|
| 99 |
* Update `syn` to v2 and `darling` to v0.20 (#578) |
| 100 |
Update proc-macro dependencies. |
| 101 |
This change should have no impact on users, but now uses the same dependency as `serde_derive`. |
| 102 |
|
| 103 |
## [2.3.2] - 2023-04-05 |
| 104 |
|
| 105 |
No changes. |
| 106 |
|
| 107 |
## [2.3.1] - 2023-03-10 |
| 108 |
|
| 109 |
No changes. |
| 110 |
|
| 111 |
## [2.3.0] - 2023-03-09 |
| 112 |
|
| 113 |
No changes. |
| 114 |
|
| 115 |
## [2.2.0] - 2023-01-09 |
| 116 |
|
| 117 |
### Fixed |
| 118 |
|
| 119 |
* `serde_with::apply` had an issue matching types when invisible token groups where in use (#538) |
| 120 |
The token groups can stem from macro_rules expansion, but should be treated mostly transparent. |
| 121 |
The old code required a group to match a group, while now groups are silently removed when checking for type patterns. |
| 122 |
|
| 123 |
## [2.1.0] - 2022-11-16 |
| 124 |
|
| 125 |
### Added |
| 126 |
|
| 127 |
* Add new `apply` attribute to simplify repetitive attributes over many fields. |
| 128 |
Multiple rules and multiple attributes can be provided each. |
| 129 |
|
| 130 |
```rust |
| 131 |
#[serde_with::apply( |
| 132 |
Option => #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")], |
| 133 |
Option<bool> => #[serde(rename = "bool")], |
| 134 |
)] |
| 135 |
#[derive(serde::Serialize)] |
| 136 |
struct Data { |
| 137 |
a: Option<String>, |
| 138 |
b: Option<u64>, |
| 139 |
c: Option<String>, |
| 140 |
d: Option<bool>, |
| 141 |
} |
| 142 |
``` |
| 143 |
|
| 144 |
The `apply` attribute will expand into this, applying the attributes to the matching fields: |
| 145 |
|
| 146 |
```rust |
| 147 |
#[derive(serde::Serialize)] |
| 148 |
struct Data { |
| 149 |
#[serde(default)] |
| 150 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 151 |
a: Option<String>, |
| 152 |
#[serde(default)] |
| 153 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 154 |
b: Option<u64>, |
| 155 |
#[serde(default)] |
| 156 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 157 |
c: Option<String>, |
| 158 |
#[serde(default)] |
| 159 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 160 |
#[serde(rename = "bool")] |
| 161 |
d: Option<bool>, |
| 162 |
} |
| 163 |
``` |
| 164 |
|
| 165 |
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>`. |
| 166 |
|
| 167 |
### Fixed |
| 168 |
|
| 169 |
* The derive macros `SerializeDisplay` and `DeserializeFromStr` now take better care not to use conflicting names for generic values. (#526) |
| 170 |
All used generics now start with `__` to make conflicts with manually written code unlikely. |
| 171 |
|
| 172 |
Thanks to @Elrendio for submitting a PR fixing the issue. |
| 173 |
|
| 174 |
## [2.0.1] - 2022-09-09 |
| 175 |
|
| 176 |
### Changed |
| 177 |
|
| 178 |
* Warn if `serde_as` is used on an enum variant. |
| 179 |
Attributes on enum variants were never supported. |
| 180 |
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)). |
| 181 |
|
| 182 |
## [2.0.0] - 2022-07-17 |
| 183 |
|
| 184 |
No changes compared to v2.0.0-rc.0. |
| 185 |
|
| 186 |
### Changed |
| 187 |
|
| 188 |
* Make `#[serde_as]` behave more intuitive on `Option<T>` fields. |
| 189 |
|
| 190 |
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. |
| 191 |
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417). |
| 192 |
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired. |
| 193 |
|
| 194 |
The `Option` field and transformation are detected by directly matching on the type name. |
| 195 |
These variants are detected as `Option`. |
| 196 |
* `Option` |
| 197 |
* `std::option::Option`, with or without leading `::` |
| 198 |
* `core::option::Option`, with or without leading `::` |
| 199 |
|
| 200 |
If an existing `default` attribute is detected, the attribute is not applied again. |
| 201 |
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`. |
| 202 |
|
| 203 |
### Fixed |
| 204 |
|
| 205 |
* Make the documentation clearer by stating that the `#[serde_as]` and `#[skip_serializing_none]` attributes must always be placed before `#[derive]`. |
| 206 |
|
| 207 |
## [2.0.0-rc.0] - 2022-06-29 |
| 208 |
|
| 209 |
### Changed |
| 210 |
|
| 211 |
* Make `#[serde_as]` behave more intuitive on `Option<T>` fields. |
| 212 |
|
| 213 |
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. |
| 214 |
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417). |
| 215 |
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired. |
| 216 |
|
| 217 |
The `Option` field and transformation are detected by directly matching on the type name. |
| 218 |
These variants are detected as `Option`. |
| 219 |
* `Option` |
| 220 |
* `std::option::Option`, with or without leading `::` |
| 221 |
* `core::option::Option`, with or without leading `::` |
| 222 |
|
| 223 |
If an existing `default` attribute is detected, the attribute is not applied again. |
| 224 |
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`. |
| 225 |
|
| 226 |
### Fixed |
| 227 |
|
| 228 |
* Make the documentation clearer by stating that the `#[serde_as]` and `#[skip_serializing_none]` attributes must always be placed before `#[derive]`. |
| 229 |
|
| 230 |
## [1.5.2] - 2022-04-07 |
| 231 |
|
| 232 |
### Fixed |
| 233 |
|
| 234 |
* Account for generics when deriving implementations with `SerializeDisplay` and `DeserializeFromStr` #413 |
| 235 |
* Provide better error messages when parsing types fails #423 |
| 236 |
|
| 237 |
## [1.5.1] - 2021-10-18 |
| 238 |
|
| 239 |
### Added |
| 240 |
|
| 241 |
* 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. |
| 242 |
|
| 243 |
More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field |
| 244 |
|
| 245 |
## [1.5.0] - 2021-09-04 |
| 246 |
|
| 247 |
### Added |
| 248 |
|
| 249 |
* Add the attribute `#[serde(borrow)]` on a field if `serde_as` is used in combination with the `BorrowCow` type. |
| 250 |
|
| 251 |
## [1.4.2] - 2021-06-07 |
| 252 |
|
| 253 |
### Fixed |
| 254 |
|
| 255 |
* Describe how the `serde_as` macro works on a high level. |
| 256 |
* The derive macros `SerializeDisplay` and `DeserializeFromStr` were relying on the prelude where they were used. |
| 257 |
Properly name all types and traits required for the expanded code to work. |
| 258 |
The tests were improved to be better able to catch such problems. |
| 259 |
|
| 260 |
## [1.4.2] - 2021-02-16 |
| 261 |
|
| 262 |
### Fixed |
| 263 |
|
| 264 |
* Fix compiling when having a struct field without the `serde_as` annotation. |
| 265 |
This broke in 1.4.0 [#267](https://github.com/jonasbb/serde_with/issues/267) |
| 266 |
|
| 267 |
## [1.4.0] - 2021-02-15 |
| 268 |
|
| 269 |
### Changed |
| 270 |
|
| 271 |
* Improve error messages when `#[serde_as(..)]` is misused as a field attribute. |
| 272 |
Thanks to @Lehona for reporting the bug in #233. |
| 273 |
* Internal cleanup for assembling and parsing attributes during `serde_as` processing. |
| 274 |
* Change processing on `#[serde_as(...)]` attributes on fields. |
| 275 |
|
| 276 |
The attributes will no longer be stripped during proc-macro processing. |
| 277 |
Instead, a private derive macro is applied to the struct/enum which captures them and makes them inert, thus allowing compilation. |
| 278 |
|
| 279 |
This should have no effect on the generated code and on the runtime behavior. |
| 280 |
It eases integration of third-party crates with `serde_with`, since they can now process the `#[serde_as(...)]` field attributes reliably. |
| 281 |
Before this, it was impossible for derive macros and lead to awkward ordering constraints on the attribute macros. |
| 282 |
|
| 283 |
Thanks to @Lehona for reporting this problem and to @dtolnay for suggesting the dummy derive macro. |
| 284 |
|
| 285 |
## [1.3.0] - 2020-11-22 |
| 286 |
|
| 287 |
### Added |
| 288 |
|
| 289 |
* Support specifying a path to the `serde_with` crate for the `serde_as` and derive macros. |
| 290 |
This is useful when using crate renaming in Cargo.toml or while re-exporting the macros. |
| 291 |
|
| 292 |
Many thanks to @tobz1000 for raising the issue and contributing fixes. |
| 293 |
|
| 294 |
### Changed |
| 295 |
|
| 296 |
* Bump minimum supported rust version to 1.40.0 |
| 297 |
|
| 298 |
## [1.2.2] - 2020-10-06 |
| 299 |
|
| 300 |
### Fixed |
| 301 |
|
| 302 |
* @adwhit contributed an improvement to `DeserializeFromStr` which allows it to deserialize from bytes (#186). |
| 303 |
This makes the derived implementation applicable in more situations. |
| 304 |
|
| 305 |
## [1.2.1] - 2020-10-04 |
| 306 |
|
| 307 |
### Fixed |
| 308 |
|
| 309 |
* The derive macros `SerializeDisplay` and `DeserializeFromStr` now use the properly namespaced types and traits. |
| 310 |
This solves conflicts with `Result` if `Result` is not `std::result::Result`, e.g., a type alias. |
| 311 |
Additionally, the code assumed that `FromStr` was in scope, which is now also not required. |
| 312 |
|
| 313 |
Thanks to @adwhit for reporting and fixing the problem in #186. |
| 314 |
|
| 315 |
## [1.2.0] - 2020-10-01 |
| 316 |
|
| 317 |
### Added |
| 318 |
|
| 319 |
* Add `serde_as` macro. Refer to the `serde_with` crate for details. |
| 320 |
* Add two derive macros, `SerializeDisplay` and `DeserializeFromStr`, which implement the `Serialize`/`Deserialize` traits based on `Display` and `FromStr`. |
| 321 |
This is in addition to the pre-existing methods like `DisplayFromStr`, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem. |
| 322 |
|
| 323 |
### Changed |
| 324 |
|
| 325 |
* Convert the code to use 2018 edition. |
| 326 |
|
| 327 |
### Fixed |
| 328 |
|
| 329 |
* The `serde_as` macro now supports serde attributes and no longer panic on unrecognized values in the attribute. |
| 330 |
|
| 331 |
## [1.2.0-alpha.3] - 2020-08-16 |
| 332 |
|
| 333 |
### Added |
| 334 |
|
| 335 |
* Add two derive macros, `SerializeDisplay` and `DeserializeFromStr`, which implement the `Serialize`/`Deserialize` traits based on `Display` and `FromStr`. |
| 336 |
This is in addition to the pre-existing methods like `DisplayFromStr`, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem. |
| 337 |
|
| 338 |
## [1.2.0-alpha.2] - 2020-08-08 |
| 339 |
|
| 340 |
### Fixed |
| 341 |
|
| 342 |
* The `serde_as` macro now supports serde attributes and no longer panic on unrecognized values in the attribute. |
| 343 |
|
| 344 |
## [1.2.0-alpha.1] - 2020-06-27 |
| 345 |
|
| 346 |
### Added |
| 347 |
|
| 348 |
* Add `serde_as` macro. Refer to the `serde_with` crate for details. |
| 349 |
|
| 350 |
### Changed |
| 351 |
|
| 352 |
* Convert the code to use 2018 edition. |
| 353 |
|
| 354 |
## [1.1.0] - 2020-01-16 |
| 355 |
|
| 356 |
### Changed |
| 357 |
|
| 358 |
* Bump minimal Rust version to 1.36.0 to support Rust Edition 2018 |
| 359 |
* Improved CI pipeline by running `cargo audit` and `tarpaulin` in all configurations now. |
| 360 |
|
| 361 |
## [1.0.1] - 2019-04-09 |
| 362 |
|
| 363 |
### Fixed |
| 364 |
|
| 365 |
* Features for the `syn` dependency were missing. |
| 366 |
This was hidden due to the dev-dependencies whose features leaked into the normal build. |
| 367 |
|
| 368 |
## [1.0.0] - 2019-04-02 |
| 369 |
|
| 370 |
Initial Release |
| 371 |
|
| 372 |
### Added |
| 373 |
|
| 374 |
* Add `skip_serializing_none` attribute, which adds `#[serde(skip_serializing_if = "Option::is_none")]` for each Option in a struct. |
| 375 |
This is helpful for APIs which have many optional fields. |
| 376 |
The effect of can be negated by adding `serialize_always` on those fields, which should always be serialized. |
| 377 |
Existing `skip_serializing_if` will never be modified and those fields keep their behavior. |