Interface ResponseUtil


public interface ResponseUtil
Utility class for ResponseEntity creation.
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static <X> org.springframework.http.ResponseEntity<X>
    wrapOrNotFound(Optional<X> maybeResponse)
    Wrap the optional into a ResponseEntity with an HttpStatus.OK status, or if it's empty, it returns a ResponseEntity with HttpStatus.NOT_FOUND.
    static <X> org.springframework.http.ResponseEntity<X>
    wrapOrNotFound(Optional<X> maybeResponse, org.springframework.http.HttpHeaders header)
    Wrap the optional into a ResponseEntity with an HttpStatus.OK status with the headers, or if it's empty, throws a ResponseStatusException with status HttpStatus.NOT_FOUND.
  • Method Details

    • wrapOrNotFound

      static <X> org.springframework.http.ResponseEntity<X> wrapOrNotFound(Optional<X> maybeResponse)
      Wrap the optional into a ResponseEntity with an HttpStatus.OK status, or if it's empty, it returns a ResponseEntity with HttpStatus.NOT_FOUND.
      Type Parameters:
      X - type of the response
      Parameters:
      maybeResponse - response to return if present
      Returns:
      response containing maybeResponse if present or HttpStatus.NOT_FOUND
    • wrapOrNotFound

      static <X> org.springframework.http.ResponseEntity<X> wrapOrNotFound(Optional<X> maybeResponse, org.springframework.http.HttpHeaders header)
      Wrap the optional into a ResponseEntity with an HttpStatus.OK status with the headers, or if it's empty, throws a ResponseStatusException with status HttpStatus.NOT_FOUND.
      Type Parameters:
      X - type of the response
      Parameters:
      maybeResponse - response to return if present
      header - headers to be added to the response
      Returns:
      response containing maybeResponse if present