There's an issue deserializing flattened structs. The below reproducer works fine for the JSON test but fails for the XML one. It panics with invalid type: map, expected a string.
Reproducer:
use serde::Deserialize;
#[derive(Deserialize)]
pub struct RecordWrapper {
pub key: String,
#[serde(flatten)]
pub data: RecordData
}
#[derive(Deserialize)]
pub struct RecordData {
foo: String,
bar: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_xml() {
let xml = r"
<Record>
<key>Record Key</key>
<foo>A</foo>
<bar>B</bar>
</Record>";
let record = quick_xml::de::from_str(xml).unwrap();
verify_record(record);
}
#[test]
fn parse_json() {
let record = serde_json::from_str(r#"{
"key": "Record Key",
"foo": "A",
"bar": "B"
}"#).unwrap();
verify_record(record);
}
fn verify_record(record: RecordWrapper) {
assert_eq!(record.key, "Record Key");
let data = record.data;
assert_eq!(data.foo, "A");
assert_eq!(data.bar, "B");
}
}
There's an issue deserializing flattened structs. The below reproducer works fine for the JSON test but fails for the XML one. It panics with
invalid type: map, expected a string
.Reproducer: