Package org.kiwiproject.jaxrs
Class KiwiEntities
- java.lang.Object
-
- org.kiwiproject.jaxrs.KiwiEntities
-
public class KiwiEntities extends Object
Static utilities related to reading entities from aResponse.
-
-
Constructor Summary
Constructors Constructor Description KiwiEntities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>safeReadEntity(javax.ws.rs.core.Response response)Read an entity as a String from the given response.static <T> Optional<T>safeReadEntity(javax.ws.rs.core.Response response, Class<T> entityType)Read an entity as an instance of the givenClassspecified byentityType.static StringsafeReadEntity(javax.ws.rs.core.Response response, String defaultMessage)Read an entity as a String from the given response.static StringsafeReadEntity(javax.ws.rs.core.Response response, Supplier<String> defaultMessageSupplier)Read an entity as a String from the given response.static <T> Optional<T>safeReadEntity(javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> entityType)Read an entity as an instance of the givenGenericTypespecified byentityType.
-
-
-
Method Detail
-
safeReadEntity
public static Optional<String> safeReadEntity(javax.ws.rs.core.Response response)
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(javax.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(javax.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(javax.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(javax.ws.rs.core.Response response, javax.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
-
-