Giter Site home page Giter Site logo

Comments (11)

oneslash avatar oneslash commented on June 2, 2024 7

Oookay, I used this use quick_xml::se::to_string; instead of current crate and works like a charm

from serde-xml-rs.

julienr avatar julienr commented on June 2, 2024 1

I managed to reduce it to this test case which fails for me on master:

#[test]
fn serialize_nested_collection() {
    #[derive(Debug, Serialize, PartialEq)]
    struct OuterCollection {
        a: Vec<A>,
    }

    #[derive(Debug, Serialize, PartialEq)]
    struct A {
        name: String,
    }

    let coll = OuterCollection {
        a: vec![A {
            name: "42".to_owned(),
        }],
    };

    let str = to_string(&coll).unwrap();
    println!("str={:?}", str);
}
running 1 test
thread 'serialize_nested_collection' panicked at 'called `Result::unwrap()` on an `Err` value: Writer { source: LastElementNameNotAvailable }', tests/test.rs:400:32
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test serialize_nested_collection ... FAILED

from serde-xml-rs.

conqp avatar conqp commented on June 2, 2024 1

Thanks. I stumbled over this just now. It appears, that serde-xml-rs is dead.

from serde-xml-rs.

rrichardson avatar rrichardson commented on June 2, 2024

Here is the debug output:

2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Struct DeleteObjectsRequest
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field delete
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Struct Delete
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field objects
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Sequence
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Struct ObjectIdentifier
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field key
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field version_id
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Some
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Struct ObjectIdentifier
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field key
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field version_id
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] None
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Struct ObjectIdentifier
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field key
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] field version_id
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser] Some
2022-09-29T18:27:21.520Z DEBUG [serde_xml_rs::ser::map] end field

from serde-xml-rs.

burleight avatar burleight commented on June 2, 2024

+1

There is a bug when serializing Vec's of struct or enum. I'm working on a fix.

from serde-xml-rs.

duckfromdiscord avatar duckfromdiscord commented on June 2, 2024

I am having this issue now too, deserializing straight into a struct and converting it straight back gives this error. i do not get it when using serde_json::to_string, so it must be on serde-xml's end.

from serde-xml-rs.

gustavowd avatar gustavowd commented on June 2, 2024

I am having tha same issue in this code:

use serde::{Deserialize, Serialize};
use serde_xml_rs::{from_str, to_string};

#[derive(Debug, Default, Deserialize, Serialize)]
struct Video {
id: u32,
title: String,
description: String,
removed: bool,
}

#[derive(Debug, Default, Deserialize, Serialize)]
struct Videos {
#[serde(rename = "Video")]
videos: Vec

fn main() {
//let file = File::open("videos.xml").expect("Unable to open file");
//let reader = BufReader::new(file);
//let videos: Videos = from_reader(reader).expect("Unable to parse XML");

//println!("Videos: {:?}", videos);

let xml_string = r#"
    <Videos>
        <Video>
            <id>1</id>
            <title>Video 1</title>
            <description>This is the first video.</description>
            <removed>false</removed>
        </Video>
        <Video>
            <id>2</id>
            <title>Video 2</title>
            <description>This is the second video.</description>
            <removed>true</removed>
        </Video>
    </Videos>
"#;

let videos: Videos = from_str(xml_string).unwrap();
println!("{:#?}", videos);

let xml_str_out = to_string(&videos).unwrap();
println!("{}", xml_str_out);

}

That's the error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: Writer { source: LastElementNameNotAvailable }', src/main.rs:45:42

Any solution?

from serde-xml-rs.

mlappo avatar mlappo commented on June 2, 2024

I have exactly the same problem... Is there any workaround?
In general vector serializing works, but if the struct has rename-serialize then it's broken...

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename(serialize = "some-parameter"))] /// !!! This is a problem, commenting this line makes it work, but produces wrong XML
struct SomeParameter {
    key: String,
    value: String,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename(serialize = "some-session"))]
struct SomeSession {
    #[serde(rename = "$value")]
    some_parameters: Vec<SomeParameter>,
}

from serde-xml-rs.

han1548772930 avatar han1548772930 commented on June 2, 2024

I also have the same error

from serde-xml-rs.

gustavowd avatar gustavowd commented on June 2, 2024

@han1548772930, use the quick_xml library. Works like a charm.
Example:
Cargo.toml
[dependencies] serde = { version = "1.0", features = ["derive"] } quick-xml = {version = "0.31.0", features = ["serialize"]}

Code:
use serde::{Deserialize, Serialize};
use quick_xml::de::from_str as from_str;
use quick_xml::se::to_string as to_string;

#[derive(Debug, Default, Deserialize, Serialize)]
struct Video {
id: u32,
#[serde(rename = "Title")]
title: String,
description: String,
removed: bool,
}

#[derive(Debug, Default, Deserialize, Serialize)]
struct Videos {
#[serde(rename = "Video")]
videos: Vec<Video>,
}

fn main() {
let xml_string = r#"<Videos> <Video> <id>1</id> <Title>Video 1</Title> <description>This is the first video.</description> <removed>false</removed> </Video> <Video> <id>2</id> <Title>Video 2</Title> <description>This is the second video.</description> <removed>true</removed> </Video> </Videos>"#;

let videos: Videos = from_str(xml_string).unwrap();
println!("{:?}", videos);

let xml_str_out = to_string(&videos).unwrap();
println!("{}", xml_str_out);

from serde-xml-rs.

han1548772930 avatar han1548772930 commented on June 2, 2024

@han1548772930, use the quick_xml library. Works like a charm. Example: Cargo.toml [dependencies] serde = { version = "1.0", features = ["derive"] } quick-xml = {version = "0.31.0", features = ["serialize"]}

Code: use serde::{Deserialize, Serialize}; use quick_xml::de::from_str as from_str; use quick_xml::se::to_string as to_string;

#[derive(Debug, Default, Deserialize, Serialize)] struct Video { id: u32, #[serde(rename = "Title")] title: String, description: String, removed: bool, }

#[derive(Debug, Default, Deserialize, Serialize)] struct Videos { #[serde(rename = "Video")] videos: Vec<Video>, }

fn main() { let xml_string = r#"<Videos> <Video> <id>1</id> <Title>Video 1</Title> <description>This is the first video.</description> <removed>false</removed> </Video> <Video> <id>2</id> <Title>Video 2</Title> <description>This is the second video.</description> <removed>true</removed> </Video> </Videos>"#;

let videos: Videos = from_str(xml_string).unwrap();
println!("{:?}", videos);

let xml_str_out = to_string(&videos).unwrap();
println!("{}", xml_str_out);

yes I have switched to quick_xml

from serde-xml-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.