Skip to content

Releases: jonasbb/serde_with

serde_with_macros v1.4.2

07 Jun 19:20
115de87
Compare
Choose a tag to compare

Fixed

  • Describe how the serde_as macro works on a high level.
  • The derive macros SerializeDisplay and DeserializeFromStr were relying on the prelude where they were used.
    Properly name all types and traits required for the expanded code to work.
    The tests were improved to be better able to catch such problems.

serde_with v1.9.1

15 May 17:04
fc2db96
Compare
Choose a tag to compare

Changed

  • NoneAsEmptyString: Deserialize using FromStr instead of using for<'a> From<&'a str> (#316)
    This will not change any behavior when applied to a field of type Option<String> as used in the documentation.
    Thanks to @mkroening for finding and fixing the issue.

serde_with v1.9.0

09 May 14:38
e90d7f4
Compare
Choose a tag to compare

Added

  • Added FromInto and TryFromInto adapters, 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],
            })
        }
    );

serde_with v1.8.1

19 Apr 20:33
4cfde28
Compare
Choose a tag to compare

Added

  • The hex::Hex type also works for u8-arrays on Rust 1.48.
    Thanks to @TheAlgorythm for raising and fixing the issue.

serde_with v1.8.0

30 Mar 21:55
4864268
Compare
Choose a tag to compare

Added

  • Added PickFirst adapter for serde_as. #291
    It allows to deserialize 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/DeserializeAs for more wrapper types. #288, #293
    This now supports:

    • Arc, sync::Weak
    • Rc, rc::Weak
    • Cell, RefCell
    • Mutex, RwLock
    • Result

Changed

  • 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.
    The new module uses IntoIterator and FromIterator as trait bound making it usable in more sitations.
    The old names continue to exist but are marked as deprecated.

Deprecated

  • Deprecated the module names serde_with::rust::btreemap_as_tuple_list and serde_with::rust::hashmap_as_tuple_list.
    You can use serde_with::rust::map_as_tuple_list as a replacement.

Fixed

  • Implement Timestamp*Seconds and Duration*Seconds also for chrono types.
    This closes #194. This was incompletely implemented in #199.

serde_with v1.7.0

24 Mar 21:52
adf9026
Compare
Choose a tag to compare

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-array crate with three important improvements:

    1. Support for the serde_as annotation.
    2. Supports non-copy elements (see serde-big-array#6).
    3. Supports arbitrary nestings of arrays (see serde-big-array#7).
  • 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 Bytes type is heavily inspired by serde_bytes and ports it to the serde_as system. (#277)

    #[serde_as(as = "Bytes")]
    value: Vec<u8>,

    Compared to serde_bytes these improvements are available

    1. Integration with the serde_as annotation (see serde-bytes#14).
    2. Implementation for arrays of arbitrary size (Rust 1.51+) (see serde-bytes#26).
  • The OneOrMany allows to deserialize a Vec from either a single element or a sequence. (#281)

    #[serde_as(as = "OneOrMany<_>")]
    cities: Vec<String>,

    This allows to deserialize from either cities: "Berlin" or cities: ["Berlin", "Paris"].
    The serialization can be configured to always emit a list with PreferMany or emit a single element with PreferOne.

serde_with v1.6.4

16 Feb 10:15
435904b
Compare
Choose a tag to compare

Fixed

  • Fix compiling when having a struct field without the serde_as annotation by updating serde_with_macros.
    This broke in 1.4.0 of serde_with_macros. #267

serde_with_macros v1.4.1

16 Feb 10:13
435904b
Compare
Choose a tag to compare

Fixed

  • Fix compiling when having a struct field without the serde_as annotation.
    This broke in 1.4.0 #267

serde_with v1.6.3

15 Feb 22:09
9bc54e0
Compare
Choose a tag to compare

Changed

  • Bump macro crate dependency (serde_with_macros) to 1.4.0 to pull in those improvements.

serde_with_macros v1.4.0

15 Feb 22:06
9bc54e0
Compare
Choose a tag to compare

Changed

  • Improve error messages when #[serde_as(..)] is misused as a field attribute.
    Thanks to @Lehona for reporting the bug in #233.

  • Internal cleanup for assembling and parsing attributes during serde_as processing.

  • Change processing on #[serde_as(...)] attributes on fields.

    The attributes will no longer be stripped during proc-macro processing.
    Instead, a private derive macro is applied to the struct/enum which captures them and makes them inert, thus allowing compilation.

    This should have no effect on the generated code and on the runtime behavior.
    It eases integration of third-party crates with serde_with, since they can now process the #[serde_as(...)] field attributes reliably.
    Before this was impossible for derive macros and lead to akward ordering constraints on the attribute macros.

    Thanks to @Lehona for reporting this problem and to @dtolnay for suggesting the dummy derive macro.