-
Notifications
You must be signed in to change notification settings - Fork 277
Closed
Labels
bughelp wantedserdeIssues related to mapping from Rust types to XMLIssues related to mapping from Rust types to XML
Description
Cargo.toml:
[package]
name = "quick-xml-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.139", features = ["derive"] }
quick-xml = { version = "0.23.0", features = ["serialize" ] }src/main.rs:
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
enum State {
A,
B,
C,
}
#[derive(Debug, Deserialize, Serialize)]
struct StateOuter {
#[serde(rename = "$value")]
state: State,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Root {
state: StateOuter,
}
impl Root {
pub fn new() -> Self {
Self { state: StateOuter { state: State::B } }
}
}
fn main() {
let xml = "<root><state>B</state></root>";
println!("Deserialized: {:?}", quick_xml::de::from_str::<Root>(&xml));
let root = Root::new();
println!("Serialized: {:?}", quick_xml::se::to_string(&root));
}Output:
Deserialized: Ok(Root { state: StateOuter { state: B } })
Serialized: Ok("<Root><state><B/></state></Root>")
Expected output:
Deserialized: Ok(Root { state: StateOuter { state: B } })
Serialized: Ok("<Root><state>B</state></Root>")
As you can see deserialization works, but serialization does not.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bughelp wantedserdeIssues related to mapping from Rust types to XMLIssues related to mapping from Rust types to XML