serde: Allow struct deserialization to ignore unknown fields
Right now #[derive(Deserialize)]
on structs and struct variants raises an error if it’s passed an unknown field. We should add an annotation that allows users to just skip these fields.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 7
- Comments: 18 (10 by maintainers)
+1 for making it a default to have deserialization not fail for unmapped fields for a few reasons.
It’s the default behavior of rustc serialize as well as many (de)serializing libraries. This is a behavior that users expect.
A client of a service may intentionally chose to not capture fields during deserialization the client application doesn’t care to allocate the extra memory to pass around. without an alternative, it’s an unavoidable tax clients have to pay.
It’s surprising user experience to have working code break with semver(sioned) services honoring contracts. It shouldn’t be a breaking change for a remote service to add fields without changing fields clients have mapped.