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
Also allowing lists to be represented with [] or implicitly #35
Comments
Hey @Gelox. Thanks for opening the issue + linking the relevant issue. I've mostly been trying to follow whatever kind of precedent Rails set with its query parser. I just had a try. It seems like it would be a fairly easy change, to allow repeating keys to deserialize as a sequence... But it wouldn't work for vectors of structs, and it doesn't seem like it would be feasible to make it compatible in the serialization direction. Given that, I would rather keep the current behaviour matching Rails. |
I've run into this sort of issue, where I'm trying to use hidden input fields to explicitly send Line 29 in 69b6269
Line 54 in 69b6269
I ended up using a |
Hey @Moggers. I'm not sure I fully follow. But maybe you could try either making the key "name[]" which would allow multiple elements? And then only use or deserialize the last element? |
Hey! Sorry, yeah it seems a bit incoherent because it started off with a call for help but I managed to figure it out a solution for myself. |
Okay that's great! I would still be a little worried that those fields could be re-ordered, and the "last entry" isn't a very robust thing to rely on. |
@samscott89 Hi, this has been a dead issue for a while and I haven't thought about it for a while, but bumps bring me back and I've reread it. This is what I've understood from the thread: it would be great to be able to support the unofficial way of passing lists via several parameters that lack an index. Either by repeating the same key with different values of adding a [] after the key. It would also probably not be very difficult to write the code that does this. My suggestion is therefore that you allow deserialization of data like this to unordered collections such as HashSet. You could support more unordered collections if you want to but I think HashSet is likely enough since 1 is so much bigger than 0. |
I think I missed this in your original question, but you can already do https://github.com/samscott89/serde_qs/blob/main/examples/introduction.rs#L118-L127 What isn't currently supported is omitting the |
The usage of HashSet instead of Vec is an interesting suggestion though. It would be a lot more explicit, and would be a pretty easy change to make. I don't think it could work for struct values though. E.g. |
Thank you, I didn't realize that |
It seems like there is no clear standardized way of representing lists in a query-string passed in with an HTTP GET operator.
However there seems to be an unofficial way that one should pass the same key with multiple values or a key with
[]
after it to indicate that it should be interpreted as a list. Here are the sources that I am getting this idea from stackoverflow and wikipedia.As far as I can tell
serde_qs
currently only supports specifying a list by indexing it like:/get_method?somelist[0]=a&somelist[1]=b
would it be interesting to also allow both an explicit list indication without an index like this:
/get_method?somelist[]=a&somelist[]=b
and an implicit list indication by assigning multiple values to the same field like this:
/get_method?somelist=a&somelist=b
What are your thoughts? Some previous discussion can be found here: seanmonstar/warp#733
The text was updated successfully, but these errors were encountered: