mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 16:55:08 +02:00
json method receives plain serialize (#2052)
This commit is contained in:
13
src/data.rs
13
src/data.rs
@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
use actix_http::error::{Error, ErrorInternalServerError};
|
||||
use actix_http::Extensions;
|
||||
use futures_util::future::{err, ok, LocalBoxFuture, Ready};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::dev::Payload;
|
||||
use crate::extract::FromRequest;
|
||||
@ -102,6 +103,18 @@ impl<T: ?Sized> From<Arc<T>> for Data<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for Data<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
||||
type Config = ();
|
||||
type Error = Error;
|
||||
|
@ -106,6 +106,18 @@ impl<T> ops::DerefMut for Form<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for Form<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
/// See [here](#extractor) for example of usage as an extractor.
|
||||
impl<T> FromRequest for Form<T>
|
||||
where
|
||||
|
@ -114,6 +114,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for Json<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates response with OK status code, correct content type header, and serialized JSON payload.
|
||||
///
|
||||
/// If serialization failed
|
||||
|
Reference in New Issue
Block a user