Closed goshleg closed 9 months ago
Hi, as the documentation says you can use Vec<T>
in combination with #[serde(default)]
, which doesn't require much boilerplate at all. Still, this is something I would like to support if possible, as I previously wrote here.
@jplatte, thanks for getting back to me so fast!
I see your point about keeping the parser stable and preventing new issues. It makes complete sense. The Vec<T>
and #[serde(default)]
combo seems to be a neat workaround to manage optional vectors without cluttering things up too much, given the library's existing functionality.
It's great to notice the conversation around this topic in the thread. A bit more clarity in the documentation could go a long way right now.
Fixed and fix released in serde_html_form 0.2.4
. There's also a follow-up issue #13 that I'd like to get feedback on.
Hello!
First off, I'd like to express my gratitude for your work on this crate; it's been immensely useful in my project!
I'm reaching out to discuss a potential enhancement regarding the deserialization functionality. While the library excels at handling
Vec<String>
, I've noticed that it doesn't entirely support deserializing form fields intoOption<Vec<String>>
.Current behavior: Deserialization directly into Vec works seamlessly. However, I encounter issues when a form field is optional. Trying to deserialize a single value like
value=1
intoOption<Vec<String>>
results inError("invalid type: string \"1\", expected a sequence")
, which suggests an unsupported case for single-item arrays. Nonetheless, if the form submits multiple items such asvalue=1&value=2
, the deserialization proceeds correctly, yieldingSome(Vec<String>)
with the expected vector.Desired Behavior: Ideally, the library should allow an optional form field to be deserialized into
Option<Vec<String>>
. When a field is present, it should handle any number of values (whether it is just one or multiple), encapsulating them into aSome(Vec<String>)
.Workaround: I have written custom deserialization logic, and here all assertion works:
Benefits: Implementing this feature would simplify dealing with optional multi-value form fields, avoiding the need for cumbersome boilerplate or manual parsing. It would be great, if single values can also be interpreted as a vector with one element, adding native support for this feature would enable more expressive and robust form handling in applications using the
serde_html_form
crate without resorting to custom implementations.I am also open to further discussion and willing to collaborate on realizing this feature.
Thank you for your time and for considering my suggestion.