Adapts a Call with response type R into the type of T. Instances are created by plain Factory a factory which is plain Retrofit.Builder#addCallAdapterFactory(Factory) installed into the Retrofit instance.
| 26 | * Retrofit.Builder#addCallAdapterFactory(Factory) installed} into the {@link Retrofit} instance. |
| 27 | */ |
| 28 | public interface CallAdapter<R, T> { |
| 29 | /** |
| 30 | * Returns the value type that this adapter uses when converting the HTTP response body to a Java |
| 31 | * object. For example, the response type for {@code Call<Repo>} is {@code Repo}. This type is |
| 32 | * used to prepare the {@code call} passed to {@code #adapt}. |
| 33 | * |
| 34 | * <p>Note: This is typically not the same type as the {@code returnType} provided to this call |
| 35 | * adapter's factory. |
| 36 | */ |
| 37 | Type responseType(); |
| 38 | |
| 39 | /** |
| 40 | * Returns an instance of {@code T} which delegates to {@code call}. |
| 41 | * |
| 42 | * <p>For example, given an instance for a hypothetical utility, {@code Async}, this instance |
| 43 | * would return a new {@code Async<R>} which invoked {@code call} when run. |
| 44 | * |
| 45 | * <pre><code> |
| 46 | * @Override |
| 47 | * public <R> Async<R> adapt(final Call<R> call) { |
| 48 | * return Async.create(new Callable<Response<R>>() { |
| 49 | * @Override |
| 50 | * public Response<R> call() throws Exception { |
| 51 | * return call.execute(); |
| 52 | * } |
| 53 | * }); |
| 54 | * } |
| 55 | * </code></pre> |
| 56 | */ |
| 57 | T adapt(Call<R> call); |
| 58 | |
| 59 | /** |
| 60 | * Creates {@link CallAdapter} instances based on the return type of {@linkplain |
| 61 | * Retrofit#create(Class) the service interface} methods. |
| 62 | */ |
| 63 | abstract class Factory { |
| 64 | /** |
| 65 | * Returns a call adapter for interface methods that return {@code returnType}, or null if it |
| 66 | * cannot be handled by this factory. |
| 67 | */ |
| 68 | public abstract @Nullable CallAdapter<?, ?> get( |
| 69 | Type returnType, Annotation[] annotations, Retrofit retrofit); |
| 70 | |
| 71 | /** |
| 72 | * Extract the upper bound of the generic parameter at {@code index} from {@code type}. For |
| 73 | * example, index 1 of {@code Map<String, ? extends Runnable>} returns {@code Runnable}. |
| 74 | */ |
| 75 | protected static Type getParameterUpperBound(int index, ParameterizedType type) { |
| 76 | return Utils.getParameterUpperBound(index, type); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Extract the raw class type from {@code type}. For example, the type representing {@code |
| 81 | * List<? extends Runnable>} returns {@code List.class}. |
| 82 | */ |
| 83 | protected static Class<?> getRawType(Type type) { |
| 84 | return Utils.getRawType(type); |
| 85 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…