Skip to content

serde_with v1.12.0

Compare
Choose a tag to compare
@github-actions github-actions released this 07 Feb 20:56
· 685 commits to master since this release
v1.12.0
c320450

Added

  • Deserialize a Vec and skip all elements failing to deserialize #383

    VecSkipError acts like a Vec, 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> #375

    The new EnumMap type converts Vec of 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*Seconds and Timestamp*SecondsWithFrac types can now be used with chrono::NaiveDateTime. #389