Add #[serde(default)] for Option parsing

If using #[serde(with = ...)] with an Option type, serde will expect all marked fields to be present. Adding #[serde(default)] restores expected behaviour - if no Option value is present, None will be used.
This commit is contained in:
philippeitis
2022-10-08 15:48:28 -07:00
parent d043fd67b9
commit ddac761e06
2 changed files with 75 additions and 9 deletions

View File

@@ -18,11 +18,13 @@ ${struct} {
#[serde(rename="${pn}")]
% endif
% if p.get("format") == "byte":
#[serde(with = "client::serde::urlsafe_base64")]
#[serde(default, with = "client::serde::urlsafe_base64")]
% elif p.get("format") == "google-duration":
#[serde(with = "client::serde::duration")]
#[serde(default, with = "client::serde::duration")]
% elif p.get("format") == "google-fieldmask":
#[serde(with = "client::serde::field_mask")]
#[serde(default, with = "client::serde::field_mask")]
% elif p.get("format") in {"uint64", "int64"}:
#[serde(default, with = "client::serde::str_like")]
% endif
pub ${mangle_ident(pn)}: ${to_rust_type(schemas, s.id, pn, p, allow_optionals=allow_optionals)},
% endfor