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 ServiceResponseWithHeaders<T,THeader> <THeader>buildEmptyWithHeaders(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.

abstract ServiceResponseWithHeaders<T,THeader> <THeader>buildWithHeaders(Response<ResponseBody> response, Class<THeader> headerType)

Build a ServiceResponseWithHeaders instance from a REST call response, a header in JSON format, and a possible error.

abstract ServiceResponse<T> build(Response<ResponseBody> response)

Build a ServiceResponse instance from a REST call response and a possible error.

abstract ServiceResponse<T> buildEmpty(Response<Void> response)

Build a ServiceResponse instance from a REST call response and a possible error, which does not have a response body.

abstract ResponseBuilder<T,E> register(int statusCode, Type type)

Register a mapping from a response status code to a response destination type.

abstract ResponseBuilder<T,E> registerError(Class<? extends RestException> type)

Register a destination type for errors with models.

Method Details

<THeader>buildEmptyWithHeaders

public abstract ServiceResponseWithHeaders buildEmptyWithHeaders(Response response, Class 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.

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:

response - the Response instance from REST call
headerType - the type of the header

Returns:

a ServiceResponseWithHeaders instance of generic type T

Throws:

java.io.IOException - exceptions from the REST call

<THeader>buildWithHeaders

public abstract ServiceResponseWithHeaders buildWithHeaders(Response response, Class headerType)

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:

response - the Response instance from REST call
headerType - the type of the header

Returns:

a ServiceResponseWithHeaders instance of generic type T

Throws:

java.io.IOException - exceptions from the REST call

build

public abstract ServiceResponse build(Response response)

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:

response - the Response instance from REST call

Returns:

a ServiceResponse instance of generic type T

Throws:

java.io.IOException - exceptions from the REST call

buildEmpty

public abstract ServiceResponse buildEmpty(Response response)

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:

response - the Response instance from REST call

Returns:

a ServiceResponse instance of generic type T

Throws:

java.io.IOException - exceptions from the REST call

register

public abstract ResponseBuilder register(int statusCode, Type type)

Register a mapping from a response status code to a response destination type.

Parameters:

statusCode - the status code.
type - the type to deserialize.

Returns:

the same builder instance.

registerError

public abstract ResponseBuilder registerError(Class type)

Register a destination type for errors with models.

Parameters:

type - the type to deserialize.

Returns:

the same builder instance.

Applies to