Skip to content

Is this result expected when serializing in the enum type? #283

@ImJeremyHe

Description

@ImJeremyHe

Thanks for your effort. It is awesome that using serde to serialize or deserialize the xml.
There are some differences in serializing enum type between the output in quick_xml and that in serde_json.

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
enum Type {
    Foo,
    Bar,
}

#[derive(Serialize, Deserialize, Debug)]
struct A {
    pub member: Type
}

fn main() {
    let data = A {member: Type::Foo};
    let json_result = serde_json::to_string(&data).unwrap();
    println!("{:?}", json_result);
    let xml_result = quick_xml::se::to_string(&data).unwrap();
    println!("{:?}", xml_result);
}

The output of this code is

"{\"member\":\"Foo\"}"
"<A><Foo/></A>"

Is this result is expected? I think it should be

"<A member="Foo"><A/>"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions