-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
PathDeserializer: use deserialize_str for deserialize_any
#2881
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
Conversation
|
Marking as semver-major for now until I dig into this change properly. In the meantime, I'd definitely like to see a test case added that would fail on master and pass on this PR. |
|
This PR adds the option to deserialize types whose |
actix-router/src/de.rs
Outdated
| // Deserializes to `String` instead of `Int` because deserializing defaults to `str` and serde doesn't automatically implement parsing numbers from `&str`s | ||
| assert_eq!(segment.1, AnyEnumDerive::String("123".to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my current hold-up. Ideally, if the AnyEnumDerive enum had Int variant before String then it should be able to deserialize to Int here. It's good that we can support it with a custom deserialize but I feel it's more distruptive to change this behavior later if it can be done at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 9c453c0.
We now does best-effort™ support for numeric values.
JohnTitor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR!
PR Type
probably bug fix?
PR Checklist
Overview
There are cases in which one might want to use types using
deserialize_anyin aweb::Path. This is especially useful forenums with fields or when the same type is also used for other things, e. g. persisting to a database.Since URLs are usually represented as Strings, I believe trying to deserialize a String if
deserialize_anyis called to be a reasonable default.Examples
In this example it is unclear to the
Deserializeimplwhether to deserialize a str or u32 and the decision is therefore left to the Deserializer.In the current version of
actix-webthis fails becausedeserialize_anyis not supported:Because this PR uses
deserialize_strfordeserialize_any, this now works as expected:Another example for a commonly used type like this is
bson::uuid::Uuid. MongoDB stores UUIDs in a map containing the binary data along with a binary subtype. However deserializing Strings or raw binary data is supported, too. Thereforedeserialize_anyis used to indicate that many formats are supported.This PR makes it possible to use types like
MyThingandbson::uuid::Uuidin aweb::Path.Closes #318