Skip to content

Serialization of Hashmap duplicate outer tag in the inners elements. Deserialization has no such problem and fails on serialized xml. #343

@julienfr112

Description

@julienfr112
quick-xml = {version = "0.23.0-alpha2", features = ["serialize"]}
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use quick_xml::de::from_str;
use quick_xml::se::to_string;

#[derive(Debug, Serialize, Deserialize)]
struct Users {
    users: HashMap<String, User>,
}
#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct Max(u16);

#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct User {
    max: Max,
}

fn main() {
    let xml = "<Users><users><roger><max>10</max></roger></users></Users";
    let users: Users = from_str(xml).unwrap();
    println!("des : {:?}", users);
    let xml2 = to_string(&users).unwrap();
    println!("res : {:?}", xml);
    println!("res : {:?}", xml2);
}

output :

des : Users { users: {"roger": User { max: Max(10) }} }
res : "<Users><users><roger><max>10</max></roger></users></Users"
res : "<Users><users><roger><users><max>10</max></users></roger></users></Users>"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom("missing field `max`")', src/main.rs:27:41
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

Labels

bughelp wantedserdeIssues related to mapping from Rust types to XML

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions