Skip to content

Incorrect serialize/deserialize struct with empty Vec field #114

Open
@XX

Description

@XX

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions