You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
there seems to be an issue with the #[serde(flatten)] attribute, as it prevents sequences with 1 element from being properly parsed. (zero or more than one work fine)
Example:
use serde::Deserialize;#[derive(Deserialize)]structSeq{#[serde(default)]seq:Vec<String>,}#[derive(Deserialize)]structWithFlatten{#[serde(flatten)]inner:Seq,}fnmain(){{// this works as expectedlet just_seq:Seq = serde_html_form::from_str("seq=1").unwrap();assert_eq!(just_seq.seq, vec!["1".to_owned()]);}{// this fails on the unwrap()// called `Result::unwrap()` on an `Err` value: Error("invalid type: string \"1\", expected a sequence")let with_flatten:WithFlatten = serde_html_form::from_str("seq=1").unwrap();assert_eq!(with_flatten.inner.seq, vec!["1".to_owned()]);}}
The text was updated successfully, but these errors were encountered:
This is an instance of serde-rs/serde#1183 and can't be fixed in thie library.
I can only strongly recommend to not use serde(flatten) when you can help it. Even when it works, it degrades performance quite a lot compared to the equivalent solution without flatten.
Hi,
there seems to be an issue with the
#[serde(flatten)]
attribute, as it prevents sequences with 1 element from being properly parsed. (zero or more than one work fine)Example:
The text was updated successfully, but these errors were encountered: