serde-xml-rs
serde-xml-rs copied to clipboard
Serializing a vector fails
Serializing struct with vector fails with:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnsupportedOperation { operation: "serialize_seq" }.
I see that unit tests contain vectors so it should be supported. But they are marked with #[ignore]
Demo code:
#[derive(Serialize, Deserialize)]
struct ABC {
abc: f32,
}
#[derive(Serialize, Deserialize)]
struct ABC2 {
#[serde(rename = "$value", default)]
items: Vec<ABC>,
}
fn main() {
let abc = ABC2 {
items: vec![ABC { abc: 1. }],
};
debug!("{:#?}", serde_xml_rs::to_string(&abc).unwrap());
}
I think this should be fixed with #129.
I get to the very end of a project and discover this doesn't work..
Also get the same for this structure
#[derive(Debug, Serialize, Deserialize)]
pub struct Data {
pub name: String,
pub list: Vec<bool>,
}
Sorry for being a bit off-topic, but I ran into the same issue as well and found a workaround: you could try to use https://github.com/tafia/quick-xml as a drop-in replacement until this issue is resolved.
@woelper That ended up being my solution too.
how can i serialize a struct with vec?!
Sorry that the serializer isn't complete yet. As soon as I have some time, I've got some stuff in the works for revamping and completing the serializer.
@Curricane, if you are in a hurry, you can have a look at the project where I did some experimentation: https://github.com/punkstarman/serde-xml
@punkstarman Does the serializer completed in #173 and mentioned as a solution to #76 also fix this issue?
If so, is there any chance of a release in the near future?
@zmrow I will check and try to release in the next week.
I just released a new version.
This appears to be fixed in the new version.