Class KiwiEntities

java.lang.Object
org.kiwiproject.jaxrs.KiwiEntities

public final class KiwiEntities extends Object
Static utilities related to reading entities from a Response.
  • Method Details

    • safeReadEntity

      public static Optional<String> safeReadEntity(jakarta.ws.rs.core.Response response)
      Read an entity as a String from the given response. If it cannot be read, return an empty Optional.
      Parameters:
      response - the response object
      Returns:
      an Optional that contains the response as a String or an empty Optional
    • safeReadEntity

      public static String safeReadEntity(jakarta.ws.rs.core.Response response, @Nullable String defaultMessage)
      Read an entity as a String from the given response. If it cannot be read, return a default message.
      Parameters:
      response - the response object
      defaultMessage - a default message to return if the response entity cannot be read (can be null)
      Returns:
      the response entity as a String or the given default message
    • safeReadEntity

      public static String safeReadEntity(jakarta.ws.rs.core.Response response, Supplier<String> defaultMessageSupplier)
      Read an entity as a String from the given response. If it cannot be read, call the given Supplier to get the default message.
      Parameters:
      response - the response object
      defaultMessageSupplier - supplies a default message if the response entity cannot be read (the Supplier can return null, but the Supplier itself must not be null)
      Returns:
      the response entity as a String or the message supplied by the given Supplier
    • safeReadEntity

      public static <T> Optional<T> safeReadEntity(jakarta.ws.rs.core.Response response, Class<T> entityType)
      Read an entity as an instance of the given Class specified by entityType. If it cannot be read, return an empty Optional.
      Type Parameters:
      T - the entity type
      Parameters:
      response - the response object
      entityType - the type of entity the response is expected to contain
      Returns:
      an Optional that contains the response as a specific type or an empty Optional
    • safeReadEntity

      public static <T> Optional<T> safeReadEntity(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> entityType)
      Read an entity as an instance of the given GenericType specified by entityType. If it cannot be read, return an empty Optional.
      Type Parameters:
      T - the entity type
      Parameters:
      response - the response object
      entityType - the type of entity the response is expected to contain
      Returns:
      an Optional that contains the response as a specific type or an empty Optional