Closed frederikhors closed 1 month ago
In the simple code below I would like to avoid the <Products> and use directly Vec<Product>:
<Products>
Vec<Product>
use quick_xml::de::from_str; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Debug)] pub struct CustomExport { // I need to directly use Vec<Product> instead of another Products struct pub Products: Vec<Product>, } #[derive(Deserialize, Serialize, Debug)] pub struct Product { pub InternalID: Option<i32>, pub Code: Option<String>, pub Description: Option<String>, } fn main() { let xml_data = r#" <CustomExport> <Products> <Product> <InternalID>1</InternalID> <Code>ABC123</Code> <Description>Product 1</Description> </Product> <Product> <InternalID>2</InternalID> <Code>DEF456</Code> <Description>Product 2</Description> </Product> </Products> </CustomExport> "#; let result: CustomExport = from_str(xml_data).unwrap(); println!("{:?}", result); }
but the result is:
CustomExport { Products: [Product { InternalID: None, Code: None, Description: None }] }
instead of the data I expect.
Why?
The explanation and way to avoid complicating model are described here
In the simple code below I would like to avoid the
<Products>
and use directlyVec<Product>
:but the result is:
instead of the data I expect.
Why?