New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vec<String> inside of struct serializes incorrectly with serde #280
Comments
dralley
changed the title
Vec<String> inside of struct serializes improperly with serde
Vec<String> inside of struct serializes incorrectly with serde
Mar 31, 2021
dralley
added a commit
to dralley/quick-xml
that referenced
this issue
Aug 11, 2021
Closed
This may be related to #205 |
dralley
added a commit
to dralley/quick-xml
that referenced
this issue
Aug 17, 2021
dralley
added a commit
to dralley/quick-xml
that referenced
this issue
Aug 22, 2021
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!! 🎉 |
Mingun
added
the
arrays
Issues related to mapping XML content onto arrays using serde
label
Aug 25, 2022
Mingun
added a commit
to Mingun/quick-xml
that referenced
this issue
Oct 1, 2022
Merged
Mingun
added a commit
to Mingun/quick-xml
that referenced
this issue
Oct 26, 2022
JOSEPHGILBY
pushed a commit
to JOSEPHGILBY/quick-xml
that referenced
this issue
Nov 5, 2022
JOSEPHGILBY
pushed a commit
to JOSEPHGILBY/quick-xml
that referenced
this issue
Nov 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.The text was updated successfully, but these errors were encountered: