Closed dralley closed 1 year ago
This may be related to https://github.com/tafia/quick-xml/pull/205
Is there a potential work around for this issue while this is still being worked on?
I guess using a custom serializer which uses serialize_field() is one option...
I'm also wondering what the workaround is here... :)
Workaround is to use a Newtype idiom:
#[test]
fn test_fail_serialize() {
const RECIPES: [&'static str; 2] = [
"pickaxe",
"crafting table",
];
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
struct Workaround(String);
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
struct RecipeBook {
recipes: Vec<Workaround>,
}
let recipe_book = RecipeBook {
recipes: RECIPES.iter().map(|s| Workaround(s.to_string())).collect(),
};
let serialized = quick_xml::se::to_string(&recipe_book).unwrap();
assert_eq!(serialized, "<RecipeBook><recipes>pickaxe</recipes><recipes>crafting table</recipes></RecipeBook>");
let deserialized: RecipeBook = from_str(&serialized).unwrap();
assert_eq!(deserialized, RecipeBook {
recipes: RECIPES.iter().map(|s| Workaround(s.to_string())).collect(),
});
}
@Mingun Thanks so much!! :tada:
I was attempting to add quick-xml to the Rust serializer benchmarks and discovered that one of the complex benchmarks serialized incorrectly, resulting in errors on deserialization. The benchmark in question is the "minecraft savedata" benchmark.
I minimized it so it's less unwieldy. Here's a test case.
Prints the following when tests are run:
The problem is that
recipes: Vec<String>
andto_be_displayed: Vec<String>
are being serialized into one long concatenated string and then assigned to an attribute of a self-closing element, rather than being serialized to a list of inner elements. Deserialize does the correct thing and expects a list of strings.