Comments (16)
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).
from serde_urlencoded.
To make things more "interesting", I would also need the Vec
to be serialized to name=val1,val2,val3,...
Would that be possible too?
from serde_urlencoded.
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.
from serde_urlencoded.
@lnicola serde_qs handles this, but in non strict mode. I have an example here.
from serde_urlencoded.
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.
from serde_urlencoded.
@samscott89 is serde_qs
supposed to handle percent-encoded brackets? s[]=1+2&s[]=2
seems to work, but s%5B%5D=1+2&s%5B%5D=2
doesn't. If I'm not missing anything, that's what browsers send for forms.
@nox serde_urlencoded
advertises support for application/x-www-form-urlencoded
, but this issue makes that feel misleading.
from serde_urlencoded.
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 serde_qs
approach roughly corresponds to "deepObject" style for example.
from serde_urlencoded.
It's not currently possible, I've wished to implement it for a while now, will probably look at it next week.
from serde_urlencoded.
I won't support the comma separated thing, but the repeated key name yes.
from serde_urlencoded.
Just to be sure to understand, you don't plan to support the repeated key name ? You suggest serde_qs for this too ?
from serde_urlencoded.
Yes, anything that requires temporary allocation won't be added to this crate.
from serde_urlencoded.
#[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 Vec<i32>
, I won't accept any such patch in this crate, but AFAIK this kind of thing isn't out of scope for serde_qs
.
from serde_urlencoded.
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 Vec, I won't accept any such patch in this crate, but AFAIK this kind of thing isn't out of scope for serde_qs.
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 foo[0]=...&foo[1]=...
or unindexed, foo[]=...&foo[]=...
.
from serde_urlencoded.
ok great @samscott89 , I'll see how to plug serde_qs
in actix then.
thanks for your replies @nox , sorry for having bothered you.
from serde_urlencoded.
How is that misleading? application/x-www-form-urlencoded
specifically doesn't have any concept of nesting or even serialising a sequence of values. This crate (and url
) does handle percent-encoded brackets, as the WHATWG URL Standard says to do it.
from serde_urlencoded.
Misleading for someone who wants to use it for something that looks like an array sent by a web browser :-).
from serde_urlencoded.
Related Issues (20)
- Support serializing maps and nested structs HOT 3
- Support serializing bytes HOT 1
- Fail to properly deserialize sequences HOT 3
- Serialize serde_json::Value::Object contains Null/None get error Custom("unsupported value")
- Missing tags for releases 0.7.0 and 0.7.1
- The following Serde URL-encoded value fails to decode HOT 1
- Is there any way to make a parameter "either bool or any other String" when deserializing?
- Serializer unable to serialize nested enums, Error:"top-level serializer supports only maps and structs" HOT 1
- Clarification request: What kind of structs can be deserialized to by this crate? HOT 3
- Release new version HOT 1
- Example for chrono::NaiveDateTime in qs HOT 5
- Please publish a new version HOT 4
- Support sequence-like values in a key-value map HOT 3
- Data did not match any variant of untagged enum
- Could we get more context on the errors? HOT 1
- Getting help section in the README is out-of-date
- Fresh serde_urlencoded v0.7.0 warning: use of deprecated associated function
- Yank serde_urlencoded 0.7.0 HOT 1
- [DISC] Percent decoding HOT 5
- Support deserializing `u128`/`i128`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serde_urlencoded.