mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.52k stars 212 forks source link

Incorrect serialize/deserialize struct with empty Vec field #114

Open XX opened 5 years ago

XX commented 5 years ago

I wrote the following test:

#[test]
fn test_empty_seq() {
    #[derive(Debug, Serialize, Deserialize, PartialEq)]
    struct Test {
        int: u32,
        seq: Vec<String>,
    }

    let test = Test {
        int: 1,
        seq: vec![],
    };
    let config = Config::try_from(&test).unwrap();

    let actual: Test = config.try_into().unwrap();
    assert_eq!(test, actual);
}

After running it displays this error:

thread 'ser::test::test_empty_seq' panicked at 'called `Result::unwrap()` on an `Err` value: missing field `seq`', src/libcore/result.rs:997:5

When I add the #[serde(default)] attribute to the seq field, it is successful, but if the struct contains only an empty-vec-field, it does not help.

matthiasbeyer commented 3 years ago

Is this still true for the latest release?

XX commented 3 years ago

Is this still true for the latest release?

Yes, this is still true for 0.11.

paologallinaharbur commented 1 month ago

Is this still an issue?

I think I've just bumped into it with Hashmasps