-
I might just be missing something or there is some incompatability somewhere but when I use the #[serde_as(as = "NoneAsEmptyString")] feature "" does become None as expected but now my true None values from a missing JSON property trigger a DeserializeBodyError. Suggestions appreciated. My code: #[serde_as]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MailParty {
pub address: String,
#[serde_as(as = "NoneAsEmptyString")]
pub name: Option<String>,
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is really helpful in understanding the problem, if you can provide a runnable example including the serialized form and the expected outcome. This is expected behavior of the serde derives. If you use |
Beta Was this translation helpful? Give feedback.
It is really helpful in understanding the problem, if you can provide a runnable example including the serialized form and the expected outcome.
This is expected behavior of the serde derives. If you use
with
ordeserialize_with
on a field, the field becomes mandatory. Theas
anddeserialize_as
boil down towith
/deserialize_with
, so the same applies here. You need to add#[serde(default)]
if you want to make the field optional.