mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 13:47:58 +00:00
fix(codegen): Take into account default=... when skip_deserializing
This commit is contained in:
@@ -249,6 +249,13 @@ impl FieldAttrs {
|
||||
// Parse `#[serde(skip_deserializing)]`
|
||||
ast::MetaItemKind::Word(ref name) if name == &"skip_deserializing" => {
|
||||
field_attrs.skip_deserializing_field = true;
|
||||
|
||||
// Initialize field to Default::default() unless a different
|
||||
// default is specified by `#[serde(default="...")]`
|
||||
if field_attrs.default_expr_if_missing.is_none() {
|
||||
let default_expr = builder.expr().default();
|
||||
field_attrs.default_expr_if_missing = Some(default_expr);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse `#[serde(skip_serializing_if="...")]`
|
||||
|
||||
@@ -437,7 +437,7 @@ fn deserialize_struct_as_seq(
|
||||
.map(|(i, &(_, ref attrs))| {
|
||||
let name = builder.id(format!("__field{}", i));
|
||||
if attrs.skip_deserializing_field() {
|
||||
let default = builder.expr().default();
|
||||
let default = attrs.expr_is_missing();
|
||||
quote_stmt!(cx,
|
||||
let $name = $default;
|
||||
).unwrap()
|
||||
@@ -1103,7 +1103,7 @@ fn deserialize_map(
|
||||
}
|
||||
},
|
||||
if attrs.skip_deserializing_field() {
|
||||
builder.expr().default()
|
||||
attrs.expr_is_missing()
|
||||
} else {
|
||||
builder.expr().id(name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user