23 KiB
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
[Unreleased]
[1.14.0] - 2022-05-29
Added
-
Add support for
timecrate v0.3 #450time::Durationcan now be serialized with theDurationSecondsand related converters.// Rust #[serde_as(as = "serde_with::DurationSeconds<u64>")] value: Duration, // JSON "value": 86400,time::OffsetDateTimeandtime::PrimitiveDateTimecan now be serialized with theTimestampSecondsand related converters.// Rust #[serde_as(as = "serde_with::TimestampMicroSecondsWithFrac<String>")] value: time::PrimitiveDateTime, // JSON "value": "1000000",time::OffsetDateTimecan be serialized in string format in different well-known formats. Two formats are supported,time::format_description::well_known::Rfc2822andtime::format_description::well_known::Rfc3339.// Rust #[serde_as(as = "time::format_description::well_known::Rfc2822")] rfc_2822: OffsetDateTime, #[serde_as(as = "Vec<time::format_description::well_known::Rfc3339>")] rfc_3339: Vec<OffsetDateTime>, // JSON "rfc_2822": "Fri, 21 Nov 1997 09:55:06 -0600", "rfc_3339": ["1997-11-21T09:55:06-06:00"], -
Deserialize
boolfrom integers #456 462Deserialize an integer and convert it into a
bool.BoolFromInt<Strict>(default) deserializes 0 tofalseand1totrue, other numbers are errors.BoolFromInt<Flexible>deserializes any non-zero astrue. Serialization only emits 0/1.// Rust #[serde_as(as = "BoolFromInt")] // BoolFromInt<Strict> b: bool, // JSON "b": 1,
Changed
- Bump MSRV to 1.53, since the new dependency
timerequires that version.
Fixed
- Make the documentation clearer by stating that the
#[serde_as]and#[skip_serializing_none]attributes must always be places before#[derive].
[1.13.0] - 2022-04-23
Added
-
Added support for
indexmap::IndexMapandindexmap::IndexSettypes. #431, #436Both 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.serde_asintegration is provided by implementing bothSerializeAsandDeserializeAsfor both types.IndexMaps can also be serialized as a list of types via theserde_as(as = "Vec<(_, _)>")annotation.All implementations are gated behind the
indexmapfeature.Thanks to @jgrund for providing parts of the implementation.
[1.12.1] - 2022-04-07
Fixed
- Depend on a newer
serde_with_macrosversion to pull in some fixes.- Account for generics when deriving implementations with
SerializeDisplayandDeserializeFromStr#413 - Provide better error messages when parsing types fails #423
- Account for generics when deriving implementations with
[1.12.0] - 2022-02-07
Added
-
Deserialize a
Vecand skip all elements failing to deserialize #383VecSkipErroracts like aVec, but elements which fail to deserialize, like the"Yellow"are ignored.#[derive(serde::Deserialize)] enum Color { Red, Green, Blue, } // JSON "colors": ["Blue", "Yellow", "Green"], // Rust #[serde_as(as = "VecSkipError<_>")] colors: Vec<Color>, // => vec![Blue, Green]Thanks to @hdhoang for creating the PR.
-
Transform between maps and
Vec<Enum>#375The new
EnumMaptype convertsVecof enums into a single map. The key is the enum variant name, and the value is the variant value.// Rust VecEnumValues(vec![ EnumValue::Int(123), EnumValue::String("Foo".to_string()), EnumValue::Unit, EnumValue::Tuple(1, "Bar".to_string()), EnumValue::Struct { a: 666, b: "Baz".to_string(), }, ] // JSON { "Int": 123, "String": "Foo", "Unit": null, "Tuple": [ 1, "Bar", ], "Struct": { "a": 666, "b": "Baz", } }
Changed
- The
Timestamp*SecondsandTimestamp*SecondsWithFractypes can now be used withchrono::NaiveDateTime. #389
[1.11.0] - 2021-10-18
Added
-
Serialize bytes as base64 encoded strings.
The character set and padding behavior can be configured.// Rust #[serde_as(as = "serde_with::base64::Base64")] value: Vec<u8>, #[serde_as(as = "Base64<Bcrypt, Unpadded>")] bcrypt_unpadded: Vec<u8>, // JSON "value": "SGVsbG8gV29ybGQ=", "bcrypt_unpadded": "QETqZE6eT07wZEO", -
The minimal supported Rust version (MSRV) is now specified in the
Cargo.tomlvia therust-versionfield. The field is supported in Rust 1.56 and has no effect on versions before.More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field
Fixed
- Fixed RUSTSEC-2020-0071 in the
timev0.1 dependency, but changing the feature flags of thechronodependency. This should not change anything. Crates requiring theoldtimefeature ofchronocan enable it separately. - Allow
HashSets with custom hashers to be deserialized when used in combination withserde_as. #408
[1.10.0] - 2021-09-04
Added
-
Add
BorrowCowwhich instructs serde to borrow data during deserialization ofCow<'_, str>,Cow<'_, [u8]>, orCow<'_, [u8; N]>. (#347) The implementation is for serde#2072 and serde#2016, about#[serde(borrow)]not working forOption<Cow<'a, str>>.#[serde_as] #[derive(Deserialize, Serialize)] struct Data<'a> { #[serde_as(as = "Option<[BorrowCow; 1]>")] nested: Option<[Cow<'a, str>; 1]>, }The
#[serde(borrow)]annotation is automatically added by the#[serde_as]attribute.
Changed
- Bump MSRV to 1.46, since the dev-dependency
bitflagsrequires that version now. flattened_maybe!no longer requires theserde_withcrate to be available with a specific name. This allows renaming the crate or usingflattened_maybe!through a re-export without any complications.
[1.9.4] - 2021-06-18
Fixed
-
with_prefix!now supports an optional visibility modifier. (#327, #328)
If not specifiedpub(self)is assumed.with_prefix!(prefix_active "active_"); // => mod {...} with_prefix!(pub prefix_active "active_"); // => pub mod {...} with_prefix!(pub(crate) prefix_active "active_"); // => pub(crate) mod {...} with_prefix!(pub(in other_mod) prefix_active "active_"); // => pub(in other_mod) mod {...}Thanks to @elpiel for raising and fixing the issue.
[1.9.3] - 2021-06-14
Added
-
The
Bytestype now supports borrowed and Cow arrays of fixed size (requires Rust 1.51+)#[serde_as(as = "Bytes")] #[serde(borrow)] borrowed_array: &'a [u8; 15], #[serde_as(as = "Bytes")] #[serde(borrow)] cow_array: Cow<'a, [u8; 15]>,Note: For borrowed arrays the used Deserializer needs to support Serde's 0-copy deserialization.
[1.9.2] - 2021-06-07
Fixed
- Suppress clippy warnings, which can occur while using
serde_conv(#320) Thanks to @mkroening for reporting and fixing the issue.
[1.9.1] - 2021-05-15
Changed
NoneAsEmptyString: Deserialize usingFromStrinstead of usingfor<'a> From<&'a str>(#316) This will not change any behavior when applied to a field of typeOption<String>as used in the documentation. Thanks to @mkroening for finding and fixing the issue.
[1.9.0] - 2021-05-09
Added
-
Added
FromIntoandTryFromIntoadapters, which enable serialization by converting into a proxy type.// Rust #[serde_as(as = "FromInto<(u8, u8, u8)>")] value: Rgb, impl From<(u8, u8, u8)> for Rgb { ... } impl From<Rgb> for (u8, u8, u8) { ... } // JSON "value": [128, 64, 32], -
New
serde_conv!macro to create conversion types with reduced boilerplate. The generated types can be used with#[serde_as]or serde's with-attribute.serde_with::serde_conv!( RgbAsArray, Rgb, |rgb: &Rgb| [rgb.red, rgb.green, rgb.blue], |value: [u8; 3]| -> Result<_, std::convert::Infallible> { Ok(Rgb { red: value[0], green: value[1], blue: value[2], }) } );
[1.8.1] - 2021-04-19
Added
- The
hex::Hextype also works for u8-arrays on Rust 1.48. Thanks to @TheAlgorythm for raising and fixing the issue.
[1.8.0] - 2021-03-30
Added
-
Added
PickFirstadapter forserde_as. #291 It allows deserializing from multiple different forms. Deserializing a number from either a number or string can be implemented like:#[serde_as(as = "PickFirst<(_, DisplayFromStr)>")] value: u32, -
Implement
SerializeAs/DeserializeAsfor more wrapper types. #288, #293 This now supports:Arc,sync::WeakRc,rc::WeakCell,RefCellMutex,RwLockResult
Changed
- Add a new
serde_with::rust::map_as_tuple_listmodule as a replacement forserde_with::rust::btreemap_as_tuple_listandserde_with::rust::hashmap_as_tuple_list. The new module usesIntoIteratorandFromIteratoras trait bound making it usable in more situations. The old names continue to exist but are marked as deprecated.
Deprecated
- Deprecated the module names
serde_with::rust::btreemap_as_tuple_listandserde_with::rust::hashmap_as_tuple_list. You can useserde_with::rust::map_as_tuple_listas a replacement.
Fixed
- Implement
Timestamp*SecondsandDuration*Secondsalso for chrono types. This closes #194. This was incompletely implemented in #199.
[1.7.0] - 2021-03-24
Added
-
Add support for arrays of arbitrary size. (#272) This feature requires Rust 1.51+.
// Rust #[serde_as(as = "[[_; 64]; 33]")] value: [[u8; 64]; 33], // JSON "value": [[0,0,0,0,0,...], [0,0,0,...], ...],Mapping of arrays was available before, but limited to arrays of length 32. All conversion methods are available for the array elements.
This is similar to the existing
serde-big-arraycrate with three important improvements:- Support for the
serde_asannotation. - Supports non-copy elements (see serde-big-array#6).
- Supports arbitrary nestings of arrays (see serde-big-array#7).
- Support for the
-
Arrays with tuple elements can now be deserialized from a map. (#272) This feature requires Rust 1.51+.
// Rust #[serde_as(as = "BTreeMap<_, _>")] value: [(String, u16); 3], // JSON "value": { "a": 1, "b": 2, "c": 3 }, -
The
Bytestype is heavily inspired byserde_bytesand ports it to theserde_assystem. (#277)#[serde_as(as = "Bytes")] value: Vec<u8>,Compared to
serde_bytesthese improvements are available- Integration with the
serde_asannotation (see serde-bytes#14). - Implementation for arrays of arbitrary size (Rust 1.51+) (see serde-bytes#26).
- Integration with the
-
The
OneOrManytype allows deserializing aVecfrom either a single element or a sequence. (#281)#[serde_as(as = "OneOrMany<_>")] cities: Vec<String>,This allows deserializing from either
cities: "Berlin"orcities: ["Berlin", "Paris"]. The serialization can be configured to always emit a list withPreferManyor emit a single element withPreferOne.
[1.6.4] - 2021-02-16
Fixed
- Fix compiling when having a struct field without the
serde_asannotation by updatingserde_with_macros. This broke in 1.4.0 ofserde_with_macros. #267
[1.6.3] - 2021-02-15
Changed
- Bump macro crate dependency (
serde_with_macros) to 1.4.0 to pull in those improvements.
[1.6.2] - 2021-01-30
Added
-
New function
serde_with::rust::deserialize_ignore_any. This function allows deserializing any data and returns the default value of the type. This can be used in conjunction with#[serde(other)]to allow deserialization of unknown data carrying enum variants.Thanks to @lovasoa for suggesting and implementing it.
[1.6.1] - 2021-01-24
Added
- Add new types similar to
DurationSecondsandTimestampSecondsbut for base units of milliseconds, microseconds, and nanoseconds. The*WithFracvariants also exist. - Add
SerializeAsimplementation for references.
Changed
- Release
Sizedtrait bound fromAs,Same,SerializeAs, andSerializeAsWrap. Only the serialize part is relaxed.
[1.6.0] - 2020-11-22
Added
-
Add
DefaultOnNullas the equivalent forrust::default_on_nullbut for theserde_assystem. -
Support specifying a path to the
serde_withcrate for theserde_asand derive macros. This is useful when using crate renaming in Cargo.toml or while re-exporting the macros.Many thanks to @tobz1000 for raising the issue and contributing fixes.
Changed
- Bump minimum supported rust version to 1.40.0
[1.5.1] - 2020-10-07
Fixed
- Depend on serde with the
derivefeature enabled. Thederivefeature is required to deserialize untagged enums which are used in theDefaultOnErrorhelpers. This fixes compilation ofserde_within scenarios where no other crate enables thederivefeature.
[1.5.0] - 2020-10-01
Added
-
The largest addition to this release is the addition of the
serde_asde/serialization scheme. It's goal is it to be a more flexible replacement to serde's with-annotation, by being more composable than before. No longer is it a problem to add a custom de/serialization adapter is the type is within anOptionor aVec.Thanks to
@markazmierczakfor the design of the trait without whom this wouldn't be possible.More details about this new scheme can be found in the also new user guide
-
This release also features a detailed user guide. The guide focusses more on how to use this crate by providing examples. For example, it includes a section about the available feature flags of this crate and how you can migrate to the shiny new
serde_asscheme. -
The crate now features de/serialization adaptors for the std and chrono's
Durationtypes. #56 #104 -
Add a
hexmodule, which allows formatting bytes (i.e.Vec<u8>) as a hexadecimal string. The formatting supports different arguments how the formatting is happening. -
Add two derive macros,
SerializeDisplayandDeserializeFromStr, which implement theSerialize/Deserializetraits based onDisplayandFromStr. This is in addition to the already existing methods likeDisplayFromStr, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem.This is part of
serde_with_macrosv1.2.0. -
Added some
serializefunctions to modules which previously had none. This makes it easier to use the conversion when also derivingSerialize. The functions simply pass through to the underlyingSerializeimplementation. This affectssets_duplicate_value_is_error,maps_duplicate_key_is_error,maps_first_key_wins,default_on_error, anddefault_on_null. -
Added
sets_last_value_winsas a replacement forsets_first_value_winswhich is deprecated now. The default behavior of serde is to prefer the first value of a set so the opposite is taking the last value. -
Added
#[serde_as]compatible conversion methods for serializing durations and timestamps as numbers. The four typesDurationSeconds,DurationSecondsWithFrac,TimestampSeconds,TimestampSecondsWithFracprovide the serialization conversion with optional subsecond precision. There is support forstd::time::Duration,chrono::Duration,std::time::SystemTimeandchrono::DateTime. Timestamps are serialized as a duration since the UNIX epoch. The serialization can be customized. It supports multiple formats, such asi64,f64, orString, and the deserialization can be tweaked if it should be strict or lenient when accepting formats.
Changed
- Convert the code to use 2018 edition.
- @peterjoel improved the performance of
with_prefix!. #101
Fixed
- The
with_prefix!macro, to add a string prefixes during serialization, now also works with unit variant enum types. #115 #116 - The
serde_asmacro now supports serde attributes and no longer panic on unrecognized values in the attribute. This is part ofserde_with_macrosv1.2.0.
Deprecated
- Deprecate
sets_first_value_wins. The default behavior of serde is to take the first value, so this module is not necessary.
[1.5.0-alpha.2] - 2020-08-16
Added
-
Add a
hexmodule, which allows formatting bytes (i.e.Vec<u8>) as a hexadecimal string. The formatting supports different arguments how the formatting is happening. -
Add two derive macros,
SerializeDisplayandDeserializeFromStr, which implement theSerialize/Deserializetraits based onDisplayandFromStr. This is in addition to the already existing methods likeDisplayFromStr, which act locally, whereas the derive macros provide the traits expected by the rest of the ecosystem.This is part of
serde_with_macrosv1.2.0-alpha.3.
Fixed
- The
serde_asmacro now supports serde attributes and no longer panic on unrecognized values in the attribute. This is part ofserde_with_macrosv1.2.0-alpha.2.
[1.5.0-alpha.1] - 2020-06-27
Added
-
The largest addition to this release is the addition of the
serde_asde/serialization scheme. It's goal is it to be a more flexible replacement to serde's with-annotation, by being more composable than before. No longer is it a problem to add a custom de/serialization adapter is the type is within anOptionor aVec.Thanks to
@markazmierczakfor the design of the trait without whom this wouldn't be possible.More details about this new scheme can be found in the also new user guide
-
This release also features a detailed user guide. The guide focusses more on how to use this crate by providing examples. For example, it includes a section about the available feature flags of this crate and how you can migrate to the shiny new
serde_asscheme. -
The crate now features de/serialization adaptors for the std and chrono's
Durationtypes. #56 #104
Changed
- Convert the code to use 2018 edition.
- @peterjoel improved the performance of
with_prefix!. #101
Fixed
- The
with_prefix!macro, to add a string prefixes during serialization, now also works with unit variant enum types. #115 #116
[1.4.0] - 2020-01-16
Added
- Add a helper to deserialize a
Vec<u8>fromString(#35) - Add
default_on_errorhelper, which turns errors intoDefaults of the type - Add
default_on_nullhelper, which turnsnullvalues intoDefaults of the type
Changed
- Bump minimal Rust version to 1.36.0
- Supports Rust Edition 2018
- version-sync depends on smallvec which requires 1.36
- Improved CI pipeline by running
cargo auditandtarpaulinin all configurations now.
[1.3.1] - 2019-04-09
Fixed
- Use
serde_with_macroswith proper dependencies specified.
[1.3.0] - 2019-04-02
Added
- Add
skip_serializing_noneattribute, which adds#[serde(skip_serializing_if = "Option::is_none")]for each Option in a struct. This is helpful for APIs which have many optional fields. The effect of can be negated by addingserialize_alwayson those fields, which should always be serialized. Existingskip_serializing_ifwill never be modified and those fields keep their behavior.
[1.2.0] - 2019-03-04
Added
- Add macro helper to support deserializing values with nested or flattened syntax #38
- Serialize tuple list as map helper
Changed
- Bumped minimal Rust version to 1.30.0
[1.1.0] - 2019-02-18
Added
- Serialize HashMap/BTreeMap as list of tuples
[1.0.0] - 2019-01-17
Added
- No changes in this release.
- Bumped version number to indicate the stability of the library.
[0.2.5] - 2018-11-29
Added
- Helper which deserializes an empty string as
Noneand otherwise usesFromStrandAsRef<str>.
[0.2.4] - 2018-11-24
Added
- De/Serialize sequences by using
DisplayandFromStrimplementations on each element. Contributed by @katyo
[0.2.3] - 2018-11-08
Added
- Add missing docs and enable deny missing_docs
- Add badges to Cargo.toml and crates.io
Changed
- Improve Travis configuration
- Various clippy improvements
[0.2.2] - 2018-08-05
Added
unwrap_or_skipallows to transparently serialize the inner part of aSome(T)- Add deserialization helper for sets and maps, inspired by comment
- Create an error if duplicate values for a set are detected
- Create an error if duplicate keys for a map are detected
- Implement a first-value wins strategy for sets/maps. This is different to serde's default which implements a last value wins strategy.
[0.2.1] - 2018-06-05
Added
- Double Option pattern to differentiate between missing, unset, or existing value
with_prefix!macro, which puts a prefix on every struct field
[0.2.0] - 2018-05-31
Added
- Add chrono support: Deserialize timestamps from int, float, and string
- Serialization of embedded JSON strings
- De/Serialization using
DisplayandFromStrimplementations - String-based collections using
DisplayandFromStr, allows deserializing "#foo,#bar"
[0.1.0] - 2017-08-17
Added
- Reserve name on crates.io