mirror of
https://github.com/actix/actix-web.git
synced 2024-11-03 15:39:50 +00:00
Add json2 HttpResponseBuilder method
This commit is contained in:
parent
8eb9eb4247
commit
7a11c2eac1
1 changed files with 8 additions and 1 deletions
|
@ -650,7 +650,14 @@ impl HttpResponseBuilder {
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
pub fn json<T: Serialize>(&mut self, value: T) -> HttpResponse {
|
pub fn json<T: Serialize>(&mut self, value: T) -> HttpResponse {
|
||||||
match serde_json::to_string(&value) {
|
self.json2(&value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set a json body and generate `HttpResponse`
|
||||||
|
///
|
||||||
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
|
pub fn json2<T: Serialize>(&mut self, value: &T) -> HttpResponse {
|
||||||
|
match serde_json::to_string(value) {
|
||||||
Ok(body) => {
|
Ok(body) => {
|
||||||
let contains = if let Some(parts) = parts(&mut self.response, &self.err)
|
let contains = if let Some(parts) = parts(&mut self.response, &self.err)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue