MCPcopy
hub / github.com/square/retrofit / CallAdapter

Interface CallAdapter

retrofit/src/main/java/retrofit2/CallAdapter.java:28–87  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

26 * Retrofit.Builder#addCallAdapterFactory(Factory) installed} into the {@link Retrofit} instance.
27 */
28public 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 * &#64;Override
47 * public &lt;R&gt; Async&lt;R&gt; adapt(final Call&lt;R&gt; call) {
48 * return Async.create(new Callable&lt;Response&lt;R&gt;&gt;() {
49 * &#64;Override
50 * public Response&lt;R&gt; 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 }

Callers 16

responseTypeMethod · 0.65
parseAnnotationsMethod · 0.65
responseTypeMethod · 0.65
responseTypeMethod · 0.65
responseTypesMethod · 0.65
responseTypesMethod · 0.65
responseTypeMethod · 0.65
responseTypesMethod · 0.65
adaptMethod · 0.65
adaptMethod · 0.65
adaptMethod · 0.65
adaptMethod · 0.65

Implementers 15

DirectCallAdapterFactoryretrofit-converters/scalars/src/test/j
ObserveOnMainCallAdapterFactorysamples/src/main/java/com/example/retr
ErrorHandlingCallAdaptersamples/src/main/java/com/example/retr
DefaultCallAdapterFactoryretrofit/src/main/java/retrofit2/Defau
BodyCallAdapterretrofit/src/main/java/retrofit2/Compl
ResponseCallAdapterretrofit/src/main/java/retrofit2/Compl
RetrofitTestretrofit/java-test/src/test/java/retro
MyCallAdapterFactoryretrofit/java-test/src/test/java/retro
GreetingCallAdapterFactoryretrofit/java-test/src/test/java/retro
RxJavaCallAdapterretrofit-adapters/rxjava/src/main/java
RxJava2CallAdapterretrofit-adapters/rxjava2/src/main/jav
BodyCallAdapterretrofit-adapters/guava/src/main/java/

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…