pub fn json(&mut self, value: impl Serialize) -> HttpResponse {
        match serde_json::to_string(&value) {
            Ok(body) => {
                let contains = if let Some(parts) = self.inner() {
                    parts.headers.contains_key(header::CONTENT_TYPE)
                } else {
                    true
                };

                if !contains {
                    self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON));
                }

                self.body(AnyBody::from(body))
            }
            Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err)),
        }
    }
/// Set a json body and generate `Response`
///
/// `HttpResponseBuilder` can not be used after this call.
Set a json body and generate `Response`
`HttpResponseBuilder` can not be used after this call.
Set a json body and generate ` Response ` ` HttpResponseBuilder ` can not be used after this call .
pub fn json(&mut self, value: impl Serialize) -> HttpResponse {
        match serde_json::to_string(&value) {
            Ok(body) => {
                let contains = if let Some(parts) = self.inner() {
                    parts.headers.contains_key(header::CONTENT_TYPE)
                } else {
                    true
                };
                if !contains {
                    self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON));
                }
                self.body(AnyBody::from(body))
            }
            Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err)),
        }
    }
pub fn json ( & mut self , value : impl Serialize ) -> HttpResponse { match serde_json :: to_string ( & value ) { Ok ( body ) => { let contains = if let Some ( parts ) = self . inner ( ) { parts . headers . contains_key ( header :: CONTENT_TYPE ) } else { true } ; if ! contains { self . insert_header ( ( header :: CONTENT_TYPE , mime :: APPLICATION_JSON ) ) ; } self . body ( AnyBody :: from ( body ) ) } Err ( err ) => HttpResponse :: from_error ( JsonPayloadError :: Serialize ( err ) ) , } }
Set a json body and generate `Response`
`HttpResponseBuilder` can not be used after this call.
Set a json body and generate ` Response ` ` HttpResponseBuilder ` can not be used after this call .
&mut self
value
impl Serialize
&mut self
value
impl Serialize