serde icon indicating copy to clipboard operation
serde copied to clipboard

Field/variant aliases are not checked for uniqueness

Open Mingun opened this issue 11 months ago • 1 comments

The code

use serde::Deserialize; // 1.0.171;
use serde_json; // 1.0.102;

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Thing {
    pub w: u8,

    #[serde(alias = "z", alias = "x")]
    pub y: u8,

    #[serde(alias = "same", alias = "other", alias = "same", alias = "x", alias = "y")]
    pub same: u8,
}

fn main() {
    let j = r#" {"j":null} "#;
    println!("{}", serde_json::from_str::<Thing>(j).unwrap_err());
}

gives the following output:

unknown field `j`, expected one of `w`, `x`, `z`, `y`, `other`, `same`, `x`, `y` at line 1 column 5

Mingun avatar Aug 02 '23 19:08 Mingun