Skip to content

Commit eb8dd88

Browse files
committed
Merge pull request square#1714 from square/jw/adapter-docs
Adapter Javadoc details.
2 parents b50cf58 + aa7a795 commit eb8dd88

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

retrofit-adapters/guava/src/main/java/retrofit2/adapter/guava/GuavaCallAdapterFactory.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.common.util.concurrent.AbstractFuture;
1919
import com.google.common.util.concurrent.ListenableFuture;
20+
import java.io.IOException;
2021
import java.lang.annotation.Annotation;
2122
import java.lang.reflect.ParameterizedType;
2223
import java.lang.reflect.Type;
@@ -26,6 +27,27 @@
2627
import retrofit2.Response;
2728
import retrofit2.Retrofit;
2829

30+
/**
31+
* A {@linkplain CallAdapter.Factory call adapter} which creates Guava futures.
32+
* <p>
33+
* Adding this class to {@link Retrofit} allows you to return {@link ListenableFuture} from service
34+
* methods.
35+
* <pre>{@code
36+
* interface MyService {
37+
* &#64;GET("user/me")
38+
* ListenableFuture<User> getUser()
39+
* }
40+
* }</pre>
41+
* There are two configurations supported for the {@code ListenableFuture} type parameter:
42+
* <ul>
43+
* <li>Direct body (e.g., {@code ListenableFuture<User>}) returns the deserialized body for 2XX
44+
* responses, sets {@link HttpException} errors for non-2XX responses, and sets {@link IOException}
45+
* for network errors.</li>
46+
* <li>Response wrapped body (e.g., {@code ListenableFuture<Response<User>>}) returns a
47+
* {@link Response} object for all HTTP responses and sets {@link IOException} for network
48+
* errors</li>
49+
* </ul>
50+
*/
2951
public final class GuavaCallAdapterFactory extends CallAdapter.Factory {
3052
public static GuavaCallAdapterFactory create() {
3153
return new GuavaCallAdapterFactory();

retrofit-adapters/java8/src/main/java/retrofit2/adapter/java8/Java8CallAdapterFactory.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package retrofit2.adapter.java8;
1717

18+
import java.io.IOException;
1819
import java.lang.annotation.Annotation;
1920
import java.lang.reflect.ParameterizedType;
2021
import java.lang.reflect.Type;
@@ -25,6 +26,27 @@
2526
import retrofit2.Response;
2627
import retrofit2.Retrofit;
2728

29+
/**
30+
* A {@linkplain CallAdapter.Factory call adapter} which creates Java 8 futures.
31+
* <p>
32+
* Adding this class to {@link Retrofit} allows you to return {@link CompletableFuture} from
33+
* service methods.
34+
* <pre>{@code
35+
* interface MyService {
36+
* &#64;GET("user/me")
37+
* CompletableFuture<User> getUser()
38+
* }
39+
* }</pre>
40+
* There are two configurations supported for the {@code CompletableFuture} type parameter:
41+
* <ul>
42+
* <li>Direct body (e.g., {@code CompletableFuture<User>}) returns the deserialized body for 2XX
43+
* responses, sets {@link HttpException} errors for non-2XX responses, and sets {@link IOException}
44+
* for network errors.</li>
45+
* <li>Response wrapped body (e.g., {@code CompletableFuture<Response<User>>}) returns a
46+
* {@link Response} object for all HTTP responses and sets {@link IOException} for network
47+
* errors</li>
48+
* </ul>
49+
*/
2850
public final class Java8CallAdapterFactory extends CallAdapter.Factory {
2951
public static Java8CallAdapterFactory create() {
3052
return new Java8CallAdapterFactory();

retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package retrofit2.adapter.rxjava;
1717

18+
import java.io.IOException;
1819
import java.lang.annotation.Annotation;
1920
import java.lang.reflect.ParameterizedType;
2021
import java.lang.reflect.Type;
@@ -43,6 +44,17 @@
4344
* Observable<User> getUser()
4445
* }
4546
* }</pre>
47+
* There are three configurations supported for the {@code Observable} type parameter:
48+
* <ul>
49+
* <li>Direct body (e.g., {@code Observable<User>}) calls {@code onNext} with the deserialized body
50+
* for 2XX responses and calls {@code onError} with {@link HttpException} for non-2XX responses and
51+
* {@link IOException} for network errors.</li>
52+
* <li>Response wrapped body (e.g., {@code Observable<Response<User>>}) calls {@code onNext}
53+
* with a {@link Response} object for all HTTP responses and calls {@code onError} with
54+
* {@link IOException} for network errors</li>
55+
* <li>Result wrapped body (e.g., {@code Observable<Result<User>>}) calls {@code onNext} with a
56+
* {@link Result} object for all HTTP responses and errors.</li>
57+
* </ul>
4658
*/
4759
public final class RxJavaCallAdapterFactory extends CallAdapter.Factory {
4860
/**

0 commit comments

Comments
 (0)