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

Open
#692 2 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
backend

Research direction

The example uses quick_xml::se::to_string and a Serde Option<usize> renamed to @foo. Start by reading the serializer’s handling of optional values and attributes, then check existing serialization tests for None. Done means determining whether None should omit the attribute or serialize it as an empty string, and adding a regression test for the agreed behavior.

Written by the indexing model from the issue text.

Description

documentation serde

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?

Dominant language
Rust
Stars
1.6k
Forks
299
Avg merge
2d 4h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tafia/quick-xml

All issues in tafia/quick-xml

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.