Closed fcoury closed 1 year ago
Found my way through the source code and figured it out - it's the max_depth
setting. This works as expected:
#[test]
fn complex_struct_and_enums() {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Query {
pub filter: Clause,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Clause {
pub operator: String,
pub items: Vec<ClauseItem>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum ClauseItem {
Clause(Clause),
Filter(Filter),
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Filter {
pub field: String,
pub operator: String,
pub value: String,
}
let query = Query {
filter: Clause {
operator: "And".to_string(),
items: vec![ClauseItem::Clause(Clause {
operator: "Or".to_string(),
items: vec![
ClauseItem::Filter(Filter {
field: "Patient.FirstName".to_string(),
operator: "Contains".to_string(),
value: "john".to_string(),
}),
ClauseItem::Filter(Filter {
field: "Patient.LastName".to_string(),
operator: "Contains".to_string(),
value: "john".to_string(),
}),
],
})],
},
};
let encoded = serde_qs::to_string(&query).unwrap();
let config = Config::new(10, true);
let decoded: Query = config.deserialize_str(&encoded).unwrap();
assert_eq!(decoded, query);
}
running 1 test
test complex_struct_and_enums ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s
I have a nested struct that is failing to be deserialized back to the original struct, giving me this error:
Here's a test case that replicates the issue:
Is this a bug or expected behavior?
Thanks!