Incorrect serialize/deserialize struct with empty Vec field
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing test_empty_seq with the shown Config::try_from and Config::try_into round trip, then inspect the serialization and deserialization paths involved. The fix is done when a struct with an empty Vec, including a struct containing only that field, round-trips without a missing-field error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100