-
Notifications
You must be signed in to change notification settings - Fork 65
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
Serialize Vec<T> #6
Comments
It's not currently possible, I've wished to implement it for a while now, will probably look at it next week. |
To make things more "interesting", I would also need the |
I won't support the comma separated thing, but the repeated key name yes. |
Hey @nbigaouette, I've created serde_qs to try and fill this gap, since I think the extra functionality needed would be unnecessarily cumbersome to this library. Let me know if it's suitable for your use case. I showed in the examples how you could also support the comma-separated vector lists (though actually the same strategy would presumably work fine here as well). |
Just to be sure to understand, you don't plan to support the repeated key name ? You suggest serde_qs for this too ? |
Yes, anything that requires temporary allocation won't be added to this crate. |
With @antoine-de we don't really understand your temporary allocation. What we need is: #[derive(Deserialize, PartialEq)]
struct Params {
foo: Vec<i32>,
}
assert_eq!(
serde_urlencoded::from_bytes(b"foo=23&foo=42"),
Ok(Params { foo: vec![23, 42] })
); If it's OK for you, we can implement it. |
#[derive(Deserialize)]
struct Params {
foo: Vec<i32>,
bar: String,
}
serde_urlencoded::from_bytes::<Params>(b"foo=23&bar=baguette&foo=42") Handling sequences mean traversing the entire string to get all the pairs with the same key, and only then you can deserialise that to a |
Yeah, this is true to the extent of my understanding. The performance of serde_qs is significantly worse than serde_urlencoded due to this, so keeping the separation seems like a good idea to me. And yes, serde_qs can handle most structs. In the case of vecs, you can either use indexed arrays |
ok great @samscott89 , I'll see how to plug thanks for your replies @nox , sorry for having bothered you. |
@samscott89 is @nox |
How is that misleading? |
Misleading for someone who wants to use it for something that looks like an array sent by a web browser :-). |
There is no standard for that and not every backend tooling handle such things with brackets. For example some Perl libraries just deserialise multiple entries with the same key as an array, which is why I decided to not support this feature in this crate directly. |
@lnicola serde_qs handles this, but in non strict mode. I have an example here. |
For the record, I agree with @nox :) An alternative potential implementation to unify the various options would follow the swagger/openapi spec: https://swagger.io/docs/specification/serialization/#query The |
I need to serialize using
serde_urlencoded::to_string()
aVec<i64>
intoname[]=val1&name[]=val2&...
.It does not seems possible
serde_urlencoded
... or am I missing something?The text was updated successfully, but these errors were encountered: