Package org.kiwiproject.jaxrs
Class KiwiEntities
java.lang.Object
org.kiwiproject.jaxrs.KiwiEntities
Static utilities related to reading entities from a
Response.-
Method Summary
Modifier and TypeMethodDescriptionsafeReadEntity(jakarta.ws.rs.core.Response response) Read an entity as a String from the given response.static StringsafeReadEntity(jakarta.ws.rs.core.Response response, @Nullable String defaultMessage) Read an entity as a String from the given response.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 givenGenericTypespecified byentityType.static <T> Optional<T>safeReadEntity(jakarta.ws.rs.core.Response response, Class<T> entityType) Read an entity as an instance of the givenClassspecified byentityType.static StringsafeReadEntity(jakarta.ws.rs.core.Response response, Supplier<String> defaultMessageSupplier) Read an entity as a String from the given response.
-
Method Details
-
safeReadEntity
Read an entity as a String from the given response. If it cannot be read, return an emptyOptional.- 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 objectdefaultMessage- 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 givenSupplierto get the default message.- Parameters:
response- the response objectdefaultMessageSupplier- 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 givenClassspecified byentityType. If it cannot be read, return an emptyOptional.- Type Parameters:
T- the entity type- Parameters:
response- the response objectentityType- 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 givenGenericTypespecified byentityType. If it cannot be read, return an emptyOptional.- Type Parameters:
T- the entity type- Parameters:
response- the response objectentityType- 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
-