ResponseBuilder<T,E> Interface
Type Parameters
- T
the body type if the status code is considered successful
- E
the exception type if the status code is considered a failure
public interface ResponseBuilder<T,E>
Defines an interface that can process a Retrofit 2 response into a deserialized body or an exception, depending on the status code registered.
Method Summary
Modifier and Type | Method and Description |
---|---|
abstract
Service |
<THeader>buildEmptyWithHeaders(Response<Void> response, Class<THeader> headerType)
Build a Service |
abstract
Service |
<THeader>buildWithHeaders(Response<ResponseBody> response, Class<THeader> headerType)
Build a Service |
abstract
Service |
build(Response<ResponseBody> response)
Build a Service |
abstract
Service |
buildEmpty(Response<Void> response)
Build a Service |
abstract
Response |
register(int statusCode, Type type)
Register a mapping from a response status code to a response destination type. |
abstract
Response |
registerError(Class<? extends RestException> type)
Register a destination type for errors with models. |
Method Details
<THeader>buildEmptyWithHeaders
public abstract ServiceResponseWithHeaders
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.
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.
Parameters:
Returns:
Throws:
<THeader>buildWithHeaders
public abstract ServiceResponseWithHeaders
Build a ServiceResponseWithHeaders instance from a REST call response, a header in JSON format, and a possible error.
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.
Parameters:
Returns:
Throws:
build
public abstract ServiceResponse
Build a ServiceResponse instance from a REST call response and a possible error.
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.
Parameters:
Returns:
Throws:
buildEmpty
public abstract ServiceResponse
Build a ServiceResponse instance from a REST call response and a possible error, which does not have a response body.
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.
Parameters:
Returns:
Throws:
register
public abstract ResponseBuilder
Register a mapping from a response status code to a response destination type.
Parameters:
Returns:
registerError
public abstract ResponseBuilder
Register a destination type for errors with models.
Parameters:
Returns: