Deserializing tag with attribute values into Map

Aperta
#383 3 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by reading the deserialization handling for internally tagged enums and $value fields, then trace how maps and sequences are populated from XML elements. The issue provides a reproducer with AttrDefChoice, AttrDef, and MultiMap; check whether the map can accept element values alongside the name attribute and add a regression case for that input. Done means the example deserializes successfully into a map, with existing behavior preserved.

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

Descrizione

help wanted serde

Assume we have below xml structure:

<container>
  <attr>
    <name>Name</name>
    <desc>Description</desc>
  </attr>
</container>

when <attr> tag doesn't have attribute values, quick-xml parses successfully into Map (HashMap, MultiMap)
Container ( "attr" : { Name(Name), Desc(Description) } )

#[derive(Deserialize, PartialEq)]
pub enum AttrDefChoice {
    Name(String),
    Desc(String),
}

#[derive(Deserialize, PartialEq)]
pub enum ContainerDef {
    Container(MultiMap<String, AttrDefChoice>),
}

but when <attr> have name value I need some wrapper struct with rename = "$value". In that case it works only with attr: Vec<AttrDefChoice>.

<container>
  <attr name="AttrName">
    <name>Name</name>
    <desc>Description</desc>
  </attr>
</container>
...

#[derive(Deserialize, PartialEq)]
pub struct AttrDef {
    name: String,

    #[serde(rename = "$value")]
    attr: MultiMap<String, AttrDefChoice>,
}

invalid type: string "Name", expected internally tagged enum AttrDefChoice

Is there any way to achieve parsing of tags with values into Map?

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.