Open vimmerru opened 3 years ago
You can steel use web::Json
for actix Json. Something like this:
use actix_web::web;
use actix_web_validator::Json;
async fn create(
req: Json<CreateRequest>,
) -> Result<web::Json<CreateResponse>> {}
or
use actix_web::web::Json;
async fn decreate(
req: actix_web_validator::Json<CreateRequest>,
) -> Result<Json<CreateResponse>> {}
@singulared Sure, the issue is more aesthetic, but there are still some practical aspects:
web::Json
instead of Json
by mistake and hard to find on code review based on diff. Code will compile well, but there will be significant issue.actix_web_validator
just too long name for prefixed import. I stopped on use actix_web_validator as web_validator
Btw, you can create a type alias for actix_web_validator::Json in your own code:
type ValidatedJson<T> = actix_web_validator::Json<T>;
Btw, you can create a type alias for actix_web_validator::Json in your own code
Usually if i need define my own types it is just sign of not well defined interface. This issue is a proposal to solve this.
In fact, this is not a new type, it is just an alias to an existing one.
use std::any::TypeId;
struct A;
type B = A;
fn main() {
assert!(TypeId::of::<A>() == TypeId::of::<B>());
}
Current suggested way is to import json extractor as
use actix_web_validator::Json
andValidatedJson
is deprecated.The problem with this approach
actix::web::Json
used not only asExtractor
, but also asResponder
and usual signature isAs a result it can't be in-place replacement and i have
use actix_web_validator::Json as ValidatedJson
in near all my endpoints.