serde-xml-rs icon indicating copy to clipboard operation
serde-xml-rs copied to clipboard

Serializing a vector fails

Open Stock84-dev opened this issue 5 years ago • 8 comments

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());
}

Stock84-dev avatar Jul 19 '20 18:07 Stock84-dev

I think this should be fixed with #129.

elmarco avatar Jul 23 '20 16:07 elmarco

I get to the very end of a project and discover this doesn't work..

ewpratten avatar May 22 '21 18:05 ewpratten

Also get the same for this structure

#[derive(Debug, Serialize, Deserialize)]
pub struct Data {
    pub name: String,
    pub list: Vec<bool>,
}

zhiburt avatar Jun 05 '21 20:06 zhiburt

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 avatar Jun 12 '21 09:06 woelper

@woelper That ended up being my solution too.

ewpratten avatar Jun 12 '21 14:06 ewpratten

how can i serialize a struct with vec?!

Curricane avatar Nov 10 '21 03:11 Curricane

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 avatar Nov 10 '21 08:11 punkstarman

@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 avatar Jul 27 '22 22:07 zmrow

@zmrow I will check and try to release in the next week.

punkstarman avatar Aug 31 '22 12:08 punkstarman

I just released a new version.

punkstarman avatar Aug 31 '22 18:08 punkstarman

This appears to be fixed in the new version.

punkstarman avatar Sep 01 '22 09:09 punkstarman