Skip to content

How to serializing Option<String> to self close element with #[serde(rename = "$unflatten={}")] #518

Closed
@LokiSharp

Description

@LokiSharp

I want to serialize a Option<String> to unflatten self close element like <Foo><option-with-none-value/></Foo>. Is there any way to control it?

Code:

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct Foo {
    #[serde(rename = "$unflatten=option-with-none-value")]
    pub body: Option<String>,
}

to_string(&Foo { body: None }).unwrap()

Result:

<Foo><option-with-none-value></option-with-none-value></Foo>

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionserdeIssues 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