Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect serialize/deserialize struct with empty Vec field #114

Open
XX opened this issue Jun 15, 2019 · 3 comments
Open

Incorrect serialize/deserialize struct with empty Vec field #114

XX opened this issue Jun 15, 2019 · 3 comments

Comments

@XX
Copy link
Contributor

XX commented Jun 15, 2019

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
Copy link
Member

Is this still true for the latest release?

matthiasbeyer added a commit to matthiasbeyer/config-rs that referenced this issue Mar 31, 2021
This patch adds the (failing) test from rust-cli#114 to validate that this issue
still exists on the latest version of the crate.

Signed-off-by: Matthias Beyer <[email protected]>
@XX
Copy link
Contributor Author

XX commented Apr 3, 2021

Is this still true for the latest release?

Yes, this is still true for 0.11.

matthiasbeyer added a commit to matthiasbeyer/config-rs that referenced this issue Jul 10, 2021
This patch adds the (failing) test from rust-cli#114 to validate that this issue
still exists on the latest version of the crate.

Signed-off-by: Matthias Beyer <[email protected]>
@paologallinaharbur
Copy link

paologallinaharbur commented Jul 17, 2024

Is this still an issue?

I think I've just bumped into it with Hashmasps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants