1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-08-02 10:45:05 +00:00

Add json2 HttpResponseBuilder method

This commit is contained in:
David McNeil 2018-08-08 11:11:15 -06:00
parent 8eb9eb4247
commit 7a11c2eac1

View file

@ -650,7 +650,14 @@ impl HttpResponseBuilder {
///
/// `HttpResponseBuilder` can not be used after this call.
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) => {
let contains = if let Some(parts) = parts(&mut self.response, &self.err)
{