Skip to content
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

Supporting string newtypes #110

Open
sabify opened this issue Sep 30, 2024 · 0 comments · May be fixed by #111
Open

Supporting string newtypes #110

sabify opened this issue Sep 30, 2024 · 0 comments · May be fixed by #111

Comments

@sabify
Copy link

sabify commented Sep 30, 2024

I just found out that string newtypes are considered sequences with single element. Is it intentional?

serde_qs/src/de/mod.rs

Lines 629 to 633 in b7278b7

Level::Flat(_) => {
// For a newtype_struct, attempt to deserialize a flat value as a
// single element sequence.
visitor.visit_seq(LevelSeq(vec![self.0].into_iter()))
}

Please consider the following case:

We define a newtype, in this case with nutype macro and we are going to use it as part of a struct:

use nutype::nutype;

#[nutype(
    sanitize(trim, lowercase),
    derive(Serialize, Deserialize)
)]
pub struct Email(String);

#[derive(Serialize, Deserialize)]
pub struct SignInReq {
    email: Email,
    // ...
}

Now when we are trying to deserialize a qs string, something like req[email][email protected], it returns error Err(Deserialization(Custom("invalid type: sequence, expected tuple struct Email"))).

@sabify sabify linked a pull request Sep 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant