T - The return type the caller expects from the REST response.E - the exception to throw in case of error.public final class ServiceResponseBuilder<T,E extends RestException> extends Object implements ResponseBuilder<T,E>
ServiceResponse.| Modifier and Type | Class and Description |
|---|---|
static class |
ServiceResponseBuilder.Factory
A factory to create a service response builder.
|
| Modifier and Type | Method and Description |
|---|---|
ServiceResponse<T> |
build(retrofit2.Response<okhttp3.ResponseBody> response)
Build a ServiceResponse instance from a REST call response and a
possible error.
|
ServiceResponse<T> |
buildEmpty(retrofit2.Response<Void> response)
Build a ServiceResponse instance from a REST call response and a
possible error, which does not have a response body.
|
<THeader> ServiceResponseWithHeaders<T,THeader> |
buildEmptyWithHeaders(retrofit2.Response<Void> response,
Class<THeader> headerType)
Build a ServiceResponseWithHeaders instance from a REST call response, a header
in JSON format, and a possible error, which does not have a response body.
|
<THeader> ServiceResponseWithHeaders<T,THeader> |
buildWithHeaders(retrofit2.Response<okhttp3.ResponseBody> response,
Class<THeader> headerType)
Build a ServiceResponseWithHeaders instance from a REST call response, a header
in JSON format, and a possible error.
|
Class<? extends RestException> |
exceptionType() |
boolean |
isSuccessful(int statusCode)
Check if the returned status code will be considered a success for
this builder.
|
ServiceResponseBuilder<T,E> |
register(int statusCode,
Type type)
Register a mapping from a response status code to a response destination type.
|
ServiceResponseBuilder<T,E> |
registerAll(Map<Integer,Type> responseTypes)
Register all the mappings from a response status code to a response
destination type stored in a
Map. |
ServiceResponseBuilder<T,E> |
registerError(Class<? extends RestException> type)
Register a destination type for errors with models.
|
ServiceResponseBuilder |
withThrowOnGet404(boolean throwOnGet404)
Specifies whether to throw on 404 responses from a GET call.
|
public ServiceResponseBuilder<T,E> register(int statusCode, Type type)
ResponseBuilderregister in interface ResponseBuilder<T,E extends RestException>statusCode - the status code.type - the type to deserialize.public ServiceResponseBuilder<T,E> registerError(Class<? extends RestException> type)
ResponseBuilderregisterError in interface ResponseBuilder<T,E extends RestException>type - the type to deserialize.public ServiceResponseBuilder<T,E> registerAll(Map<Integer,Type> responseTypes)
Map.responseTypes - the mapping from response status codes to response types.public ServiceResponse<T> build(retrofit2.Response<okhttp3.ResponseBody> response) throws IOException
ResponseBuilderIf the status code in the response is registered, the response will be considered valid and deserialized into the specified destination type. If the status code is not registered, the response will be considered invalid and deserialized into the specified error type if there is one. An AutoRestException is also thrown.
build in interface ResponseBuilder<T,E extends RestException>response - the Response instance from REST callTIOException - exceptions from deserializationpublic ServiceResponse<T> buildEmpty(retrofit2.Response<Void> response) throws IOException
ResponseBuilderIf the status code in the response is registered, the response will be considered valid. If the status code is not registered, the response will be considered invalid. An AutoRestException is also thrown.
buildEmpty in interface ResponseBuilder<T,E extends RestException>response - the Response instance from REST callTIOException - exceptions from deserializationpublic <THeader> ServiceResponseWithHeaders<T,THeader> buildWithHeaders(retrofit2.Response<okhttp3.ResponseBody> response, Class<THeader> headerType) throws IOException
ResponseBuilderIf the status code in the response is registered, the response will be considered valid and deserialized into the specified destination type. If the status code is not registered, the response will be considered invalid and deserialized into the specified error type if there is one. An AutoRestException is also thrown.
buildWithHeaders in interface ResponseBuilder<T,E extends RestException>THeader - the type of the headerresponse - the Response instance from REST callheaderType - the type of the headerTIOException - exceptions from deserializationpublic <THeader> ServiceResponseWithHeaders<T,THeader> buildEmptyWithHeaders(retrofit2.Response<Void> response, Class<THeader> headerType) throws IOException
ResponseBuilderIf the status code in the response is registered, the response will be considered valid. If the status code is not registered, the response will be considered invalid. An AutoRestException is also thrown.
buildEmptyWithHeaders in interface ResponseBuilder<T,E extends RestException>THeader - the type of the headerresponse - the Response instance from REST callheaderType - the type of the headerTIOException - exceptions from deserializationpublic Class<? extends RestException> exceptionType()
public boolean isSuccessful(int statusCode)
statusCode - the status code to checkpublic ServiceResponseBuilder withThrowOnGet404(boolean throwOnGet404)
throwOnGet404 - true if to throw; false to simply return null. Default is false.Copyright © 2019. All rights reserved.