Skip to content

Is it as expect that Option attribute serialize into empty string instead of non-attribute. #692

Open
@Vonfry

Description

@Vonfry

A simple example here.

use serde::Serialize;
use quick_xml::se::to_string;

#[derive(Serialize)]
struct Foo {
    #[serde(rename = "@foo")]
    foo: Option<usize>
}

#[test]
fn test_foo() {
    let foo = Foo { foo: None };

    let foo_xml = to_string(&foo).unwrap();

    assert_eq!(foo_xml, "<Foo foo=\"\"/>");
    assert_eq!(foo_xml, "<Foo/>");
}

Is foo="" expected in quick-xml instead of dismissing this attribute?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationIssues about improvements or bugs in documentationserdeIssues 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