Skip to content

Write comment when using serde serialization? #812

Open
@sydhds

Description

Is there a way to add comments when using quick_xml serde serialization? I've tried to implement something like:

#[derive(Debug, PartialEq, Default, Deserialize)]
struct XbelHighestId(u64);

pub fn serialize_highest_id<S>(
    highest_id: &XbelHighestId,
    serializer: S,
) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    let comment = format!(r#"<!--- highestId :{}: -->"#, highest_id.0);
    serializer.serialize_str(&comment)
}

struct Xbel {
    [...]
    #[serde(serialize_with = "serialize_highest_id", rename = "$text")]
    highest_id: XbelHighestId,
}

but serialize_str transform '<' & '>' character into their xml equivalent...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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