Skip to content

How to deserialize an element contains empty string? #795

@jianse

Description

@jianse
#[derive(Debug, Deserialize)]
struct Text {
    #[serde(rename = "$value")]
    text: String,
}

#[test]
fn test_de() -> Result<()> {
    let xml = r#"<Text> </Text>"#;
    let txt: Text = quick_xml::de::from_str(xml)?;
    let txt = dbg!(txt);
    assert_eq!(txt.text, " ");
    Ok(())
}

expect an write space, but gives an error.

Error: missing field `$value`

Metadata

Metadata

Assignees

No one assigned

    Labels

    serdeIssues 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