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

On master branch rocket_contrib, FromRequest not implemented for Json<T> #1572

Closed
DanielJoyce opened this issue Mar 11, 2021 · 5 comments
Closed
Labels
no bug The reported bug was confirmed nonexistent

Comments

@DanielJoyce
Copy link

the trait bound rocket_contrib::json::Json<CreateProjectFolderRequest>: FromRequest<'_, '_> is not satisfied
the trait FromRequest<'_, '_> is not implemented for rocket_contrib::json::Json<CreateProjectFolderRequest>

use rocket_contrib::json::Json;

#[post("/users", format = "json", data = "<user>")]
fn new_user(user: Json<User>) {
    /* ... */
}

This won't work from the docs.

@DanielJoyce
Copy link
Author

rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev", features = ["uuid"] }

json is a default feature, and works in all other ways. It's just the data guard doesn't work

@DanielJoyce
Copy link
Author

Looking at the source it appears FromRequest is missing.

@SergioBenitez
Copy link
Member

SergioBenitez commented Mar 11, 2021

Json is not and has never been a request guard, and thus does not implement FromRequest. It is a data guard, however, and does implement FromData. This is true in master. Many, many tests check for this. That exact docstring is tested, for instance.

I suspect you have a typo in your program or are not using the data route argument. If the former, Rocket will tell you which parameters are extra or missing. If the latter, you'll see the type mismatch error since you'll have used Json as a request guard.

@SergioBenitez SergioBenitez added the no bug The reported bug was confirmed nonexistent label Mar 11, 2021
@SergioBenitez
Copy link
Member

SergioBenitez commented Mar 11, 2021

What does "pure" JSON mean? Is it just JSON? Then Json. I'm not sure how we can be clearer than what the docs say now:

To parse request body data as JSON , add a data route argument with a target type of Json<T>, where T is some type you’d like to parse from JSON. T must implement serde::Deserialize.

@DanielJoyce
Copy link
Author

Doesn't matter. Figured it out. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no bug The reported bug was confirmed nonexistent
Projects
None yet
Development

No branches or pull requests

2 participants