Class ResponseMapper


  • @Component
    public class ResponseMapper
    extends Object
    ResponseMapper class should be used for success responses mapping only. In case of unsuccessful error mapping IllegalArgumentException would be thrown - ResponseErrorMapper should be used for such cases.
    • Constructor Summary

      Constructors 
      Constructor Description
      ResponseMapper()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> org.springframework.http.ResponseEntity accepted​(ResponseObject<T> response)
      Generates ResponseEntity with the response body in response to a request that hasn't been processed yet
      <T> org.springframework.http.ResponseEntity created​(ResponseObject<T> response)
      Generates ResponseEntity with the response body in response to a successful resource creation request
      <T> org.springframework.http.ResponseEntity created​(ResponseObject<T> response, ResponseHeaders responseHeaders)
      Generates ResponseEntity with the response body in response to a successful resource creation request
      <T,​R>
      org.springframework.http.ResponseEntity<?>
      created​(ResponseObject<T> response, Function<T,​R> mapper)
      Generates ResponseEntity with the response body in response to a successful resource creation request
      <T,​R>
      org.springframework.http.ResponseEntity<?>
      created​(ResponseObject<T> response, Function<T,​R> mapper, ResponseHeaders responseHeaders)
      Generates ResponseEntity with the response body in response to a successful resource creation request
      <T> org.springframework.http.ResponseEntity delete​(ResponseObject<T> response)
      Generates ResponseEntity with the response body in response to a successful resource deletion request
      <T,​R>
      org.springframework.http.ResponseEntity<?>
      delete​(ResponseObject<T> response, Function<T,​R> mapper)
      Generates ResponseEntity with the response body in response to a successful resource deletion request
      <T> org.springframework.http.ResponseEntity ok​(ResponseObject<T> response)
      Generates ResponseEntity with the response body in response to a generic successful request
      <T,​R>
      org.springframework.http.ResponseEntity<?>
      ok​(ResponseObject<T> response, Function<T,​R> mapper)
      Generates ResponseEntity with the response body in response to a generic successful request
      <T,​R>
      org.springframework.http.ResponseEntity<?>
      ok​(ResponseObject<T> response, Function<T,​R> mapper, ResponseHeaders responseHeaders)
      Generates ResponseEntity with the response body and headers in response to a generic successful request
    • Constructor Detail

      • ResponseMapper

        public ResponseMapper()
    • Method Detail

      • ok

        public <T,​R> org.springframework.http.ResponseEntity<?> ok​(ResponseObject<T> response,
                                                                         Function<T,​R> mapper)
        Generates ResponseEntity with the response body in response to a generic successful request
        Type Parameters:
        T - type of the body in the response object
        R - type of the transformed body
        Parameters:
        response - response object from the service with the body inside
        mapper - function for transforming body into another type
        Returns:
        response entity with OK HTTP status and body
      • created

        public <T,​R> org.springframework.http.ResponseEntity<?> created​(ResponseObject<T> response,
                                                                              Function<T,​R> mapper)
        Generates ResponseEntity with the response body in response to a successful resource creation request
        Type Parameters:
        T - type of the body in the response object
        R - type of the transformed body
        Parameters:
        response - response object from the service with the body inside
        mapper - function for transforming body into another type
        Returns:
        response entity with Created HTTP status and body
      • delete

        public <T,​R> org.springframework.http.ResponseEntity<?> delete​(ResponseObject<T> response,
                                                                             Function<T,​R> mapper)
        Generates ResponseEntity with the response body in response to a successful resource deletion request
        Type Parameters:
        T - type of the body in the response object
        R - type of the transformed body
        Parameters:
        response - response object from the service with the body inside
        mapper - function for transforming body into another type
        Returns:
        response entity with No Content HTTP status and body
      • ok

        public <T,​R> org.springframework.http.ResponseEntity<?> ok​(ResponseObject<T> response,
                                                                         Function<T,​R> mapper,
                                                                         ResponseHeaders responseHeaders)
        Generates ResponseEntity with the response body and headers in response to a generic successful request
        Type Parameters:
        T - type of the body in the response object
        R - type of the body after applying mapper
        Parameters:
        response - response object from the service with the body inside
        mapper - function for transforming body into another type
        responseHeaders - headers to be returned in the response
        Returns:
        response entity with OK HTTP status, body and headers
      • created

        public <T,​R> org.springframework.http.ResponseEntity<?> created​(ResponseObject<T> response,
                                                                              Function<T,​R> mapper,
                                                                              ResponseHeaders responseHeaders)
        Generates ResponseEntity with the response body in response to a successful resource creation request
        Type Parameters:
        T - type of the body in the response object
        R - type of the body after applying mapper
        Parameters:
        response - response object from the service with the body inside
        mapper - function for transforming body into another type
        responseHeaders - headers to be returned in the response
        Returns:
        response entity with Created HTTP status, body and headers
      • created

        public <T> org.springframework.http.ResponseEntity created​(ResponseObject<T> response,
                                                                   ResponseHeaders responseHeaders)
        Generates ResponseEntity with the response body in response to a successful resource creation request
        Type Parameters:
        T - type of the body in the response object
        Parameters:
        response - response object from the service with the body inside
        responseHeaders - headers to be returned in the response
        Returns:
        response entity with Created HTTP status, body and headers
      • ok

        public <T> org.springframework.http.ResponseEntity ok​(ResponseObject<T> response)
        Generates ResponseEntity with the response body in response to a generic successful request
        Type Parameters:
        T - type of the body in the response object
        Parameters:
        response - response object from the service with the body inside
        Returns:
        response entity with OK HTTP status and body
      • created

        public <T> org.springframework.http.ResponseEntity created​(ResponseObject<T> response)
        Generates ResponseEntity with the response body in response to a successful resource creation request
        Type Parameters:
        T - type of the body in the response object
        Parameters:
        response - response object from the service with the body inside
        Returns:
        response entity with Created HTTP status and body
      • delete

        public <T> org.springframework.http.ResponseEntity delete​(ResponseObject<T> response)
        Generates ResponseEntity with the response body in response to a successful resource deletion request
        Type Parameters:
        T - type of the body in the response object
        Parameters:
        response - response object from the service with the body inside
        Returns:
        response entity with No Content HTTP status and body
      • accepted

        public <T> org.springframework.http.ResponseEntity accepted​(ResponseObject<T> response)
        Generates ResponseEntity with the response body in response to a request that hasn't been processed yet
        Type Parameters:
        T - type of the body in the response object
        Parameters:
        response - response object from the service with the body inside
        Returns:
        response entity with Accepted HTTP status and body