iddm / serde-aux

An auxiliary serde library providing helpful functions for serialisation and deserialisation for containers, struct fields and others.
MIT License
152 stars 26 forks source link

deserialize_option_number_from_string does not seem to allow non-existent values #36

Closed sffc closed 1 year ago

sffc commented 1 year ago

Normally when you deserialize something like

{
  "a": 1
}

into a Serde struct like

#[derive(Deserialize)]
struct Foo {
  a: Option<String>,
  b: Option<String>,
}

the deserialization succeeds, putting a None into the b field. However, if I apply deserialize_with = deserialize_option_number_from_string to that field, then I get an error that the field b is missing.

CC @younies

sffc commented 1 year ago

I see, it seems the field needs to be annotated with #[serde(default)].