T
- the body type if the status code is considered successfulE
- the exception type if the status code is considered a failurepublic interface ResponseBuilder<T,E extends RestException>
Modifier and Type | Interface and Description |
---|---|
static interface |
ResponseBuilder.Factory
A factory that creates a builder based on the return type and the exception type.
|
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.
|
ResponseBuilder<T,E> |
register(int statusCode,
Type type)
Register a mapping from a response status code to a response destination type.
|
ResponseBuilder<T,E> |
registerError(Class<? extends RestException> type)
Register a destination type for errors with models.
|
ResponseBuilder<T,E> register(int statusCode, Type type)
statusCode
- the status code.type
- the type to deserialize.ResponseBuilder<T,E> registerError(Class<? extends RestException> type)
type
- the type to deserialize.ServiceResponse<T> build(retrofit2.Response<okhttp3.ResponseBody> response) throws IOException
If 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.
response
- the Response
instance from REST callT
E
- exceptions from the REST callIOException
- exceptions from deserializationServiceResponse<T> buildEmpty(retrofit2.Response<Void> response) throws IOException
If 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.
response
- the Response
instance from REST callT
E
- exceptions from the REST callIOException
- exceptions from deserialization<THeader> ServiceResponseWithHeaders<T,THeader> buildWithHeaders(retrofit2.Response<okhttp3.ResponseBody> response, Class<THeader> headerType) throws IOException
If 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.
THeader
- the type of the headerresponse
- the Response
instance from REST callheaderType
- the type of the headerT
E
- exceptions from the REST callIOException
- exceptions from deserialization<THeader> ServiceResponseWithHeaders<T,THeader> buildEmptyWithHeaders(retrofit2.Response<Void> response, Class<THeader> headerType) throws IOException
If 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.
THeader
- the type of the headerresponse
- the Response
instance from REST callheaderType
- the type of the headerT
E
- exceptions from the REST callIOException
- exceptions from deserializationCopyright © 2019. All rights reserved.