Problem deserializing a struct that can be serialized
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
Direzione di ricerca
Start with the issue’s minimal Rust example and its failing deserialization tests, especially the Source enum and the source field’s serde(rename = "Source") attribute. Check quick-xml’s deserialization behavior for repeated XML elements and enum values; done means the shown XML deserializes to the expected Sources values while the serialization test still passes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have a Problem de serializing the following xml
<Sources>
<Source>A</Source>
<Source>B</Source>
</Sources>
This is my current attempt
/*
[dependencies]
serde = { version = "1.0", features = ["derive"] }
quick-xml = {version="0.31", features = ["serialize"]}
*/
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Sources {
#[serde(rename = "Source")]
source: Vec<Source>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
enum Source {
A,
B,
}
#[cfg(test)]
mod tests {
use quick_xml::de::from_str;
use super::*;
#[test]
fn test_serialize_sources() {
let sources = Sources {
source: vec![Source::A, Source::B],
};
let xml = r#"<Sources><Source>A</Source><Source>B</Source></Sources>"#;
let serialized = to_string(&sources).expect("Failed to serialize sources"); // Use the to_string function from quick_xml
assert_eq!(serialized, xml);
}
#[test]
fn test_deserialize_sources(){
let xml = r#"<Sources><Source>A</Source><Source>B</Source></Sources>"#;
let sources = Sources{ source: vec![Source::A, Source::B]};
let deserialize = from_str::<Sources>(&xml).expect("Failed to deserialize sources");
assert_eq!(deserialize, sources);
}
#[test]
fn test_deserialize_source(){
let xml = r#"<Sources><Source>B</Source></Sources>"#;
let sources = Sources{ source: vec![Source::B]};
let deserialize = from_str::<Sources>(&xml).expect("Failed to deserialize sources");
assert_eq!(deserialize, sources);
}
}
which fails with the following error
running 3 tests
test tests::test_deserialize_sources ... FAILED
test tests::test_serialize_sources ... ok
test tests::test_deserialize_source ... FAILED
failures:
---- tests::test_deserialize_sources stdout ----
thread 'tests::test_deserialize_sources' panicked at src/main.rs:45:53:
Failed to deserialize sources: Custom("unknown variant `Source`, expected `A` or `B`")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- tests::test_deserialize_source stdout ----
thread 'tests::test_deserialize_source' panicked at src/main.rs:54:53:
Failed to deserialize sources: Custom("unknown variant `Source`, expected `A` or `B`")
failures:
tests::test_deserialize_source
tests::test_deserialize_sources
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass `--bin example_issue_quick_xml`
❯
- Lingua principale
- Rust
- Stelle
- 1.6k
- Fork
- 299
- Merge medio
- 2g 4h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tafia/quick-xml
-
Parser accepts an empty element or attribute nameForse già presa @ychampion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytesForse già presa @emschwartz l’ha presa 4 giorni fa. Apertabug encoding
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
tafia/quick-xml#1040 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
encoding optimization
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
tafia/quick-xml#1039 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
optimization question
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 1-2 giorni Idoneità per principianti 53/100
tafia/quick-xml#1035 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tafia/quick-xml
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
storytold/photocraft#14822 ·
I maintainer di solito rispondono entro 1 giorno
-
bug css
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
dginev/latexml-oxide#853 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 2 giorni
-
[Bug] export_build_environment admits its output directory only after the export ran in the build computerForse già presa @viniciusdsandrade l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno