This adds support for query strings in which a sequence field of a
`Deserialize` / `Serialize` struct is (de)serialized as
`field=val1&field=val2&field=val3`, instead of the more common
`field[]=val1&field[]=val2&field[]=val3` syntax.
68: Allow serialization of unit type r=nox a=maxv-rust
That changes provides support for unit type serialization.
It may looks like it doesn't make sense to serialize `()`. Unfortunately that kind of serialization may be necessary for generic structures where one of generic argument may be `()`.
Closes#69
Co-authored-by: MaxV <60802079+maxv-rust@users.noreply.github.com>
64: Add Error::source r=nox a=AnderEnder
As discussed in https://github.com/nox/serde_urlencoded/pull/63 `Error::source` was added in `1.30.0`
This PR implements `Error::source`
Co-authored-by: Andrii Radyk <ander.ender@gmail.com>
59: Expose lifetimes in UrlEncodedSerializer r=nox a=benesch
Forcing UrlEncodedSerializer to have a 'static lifetime is unnecessarily
restrictive and breaks a downstream dependency, reqwest. Thread a new
lifetime through to fix the problem.
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
Forcing UrlEncodedSerializer to have a 'static lifetime is unnecessarily
restrictive and breaks a downstream dependency, reqwest. Thread a new
lifetime through to fix the problem.
45: Fix struct newtype deserialization (and add tests) r=nox a=samsieber
Fixes#41
I only had to fix the deserializer - the serialization already works. So now they work the same way - you can serialize something and then deserialize it losslessly.
I also added tests for serialization and deserialization. Let me know if there's anything you'd like changed.
Co-authored-by: Sam Sieber <swsieber@gmail.com>
30: Support deserializing a (keyword) string into a unit-only enum r=nox a=smangelsdorf
This adds support for deserializing a structure such as:
```rust
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
enum SortOrder {
Asc,
Desc,
}
#[derive(Serialize, Deserialize, Debug)]
struct SearchOptions {
sort: SortOrder,
}
```
This is already supported for serialization (and I've added a test case for the existing support as part of this PR), but attempting to deserialize the string `"sort=asc"` would result in the error:
```
invalid type: string "asc", expected enum SortOrder
```
I've made a sample in the playground of the way this is handled in `serde_urlencoded` vs `serde_json`: https://play.rust-lang.org/?gist=75fc1e5bbbc1eec29a472373d47488a0&version=stable
This brings the behaviour in line with the way `serde_json` currently handles this case, which I hope is appropriate. Happy to tweak the behaviour if there's a better way to handle it.
Co-authored-by: Shaun Mangelsdorf <s.mangelsdorf@gmail.com>