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

Aperta
#692 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
Rust
Stelle
1.6k
Fork
299
Merge medio
2g 4h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tafia/quick-xml

Tutte le issue di tafia/quick-xml

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.