dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
964 stars 164 forks source link

No error on unknown field #244

Closed sidju closed 2 years ago

sidju commented 2 years ago

This may be because I have tagged my structs with serde(default, rename_all = "camelCase"), but when my source file contains a field that isn't handled the deserializer just ignores it instead of raising an error.

Is it the intended behaviour to not raise an error on unhandled fields when deserializing yaml? Is there some feature I'm missing to change this behaviour?

sidju commented 2 years ago

Example code to show the issue: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=94d7a3f065abfc116c3648befd9fdd13 (Note how size from the input is silently dropped)

jonasbb commented 2 years ago

I think you might be looking for #[serde(deny_unknown_fields)]. https://serde.rs/container-attrs.html#deny_unknown_fields

sidju commented 2 years ago

I don't know how I missed that... (except probably coding when I should have been sleeping) Thank you, and sorry for taking up your time with such a stupid mistake.