diff --git a/pom.xml b/pom.xml
index 722d91698b..7b0aa7977a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,7 +75,7 @@
4.121.7.01.9.5
- 3.0
+ 3.2
diff --git a/retrofit/src/main/java/retrofit2/OptionalConverterFactory.java b/retrofit/src/main/java/retrofit2/OptionalConverterFactory.java
index 7174e3ad8f..a9325322c3 100644
--- a/retrofit/src/main/java/retrofit2/OptionalConverterFactory.java
+++ b/retrofit/src/main/java/retrofit2/OptionalConverterFactory.java
@@ -24,11 +24,7 @@
import okhttp3.ResponseBody;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
-/**
- * A {@linkplain Converter.Factory converter} for {@code Optional} which delegates to another
- * converter to deserialize {@code T} and then wraps it into {@link Optional}.
- */
-@IgnoreJRERequirement
+@IgnoreJRERequirement // Only added when Optional is available (Java 8+ / Android API 24+).
final class OptionalConverterFactory extends Converter.Factory {
static final Converter.Factory INSTANCE = new OptionalConverterFactory();
diff --git a/retrofit/src/main/java/retrofit2/Platform.java b/retrofit/src/main/java/retrofit2/Platform.java
index 270a8040ae..dcaf317e91 100644
--- a/retrofit/src/main/java/retrofit2/Platform.java
+++ b/retrofit/src/main/java/retrofit2/Platform.java
@@ -22,6 +22,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;
@@ -149,6 +150,16 @@ static class Android extends Platform {
return singletonList(new ExecutorCallAdapterFactory(callbackExecutor));
}
+ @Override List extends Converter.Factory> defaultConverterFactories() {
+ return Build.VERSION.SDK_INT >= 24
+ ? singletonList(OptionalConverterFactory.INSTANCE)
+ : Collections.emptyList();
+ }
+
+ @Override int defaultConverterFactoriesSize() {
+ return Build.VERSION.SDK_INT >= 24 ? 1 : 0;
+ }
+
static class MainThreadExecutor implements Executor {
private final Handler handler = new Handler(Looper.getMainLooper());
diff --git a/retrofit/src/test/java/retrofit2/OptionalConverterFactoryAndroidTest.java b/retrofit/src/test/java/retrofit2/OptionalConverterFactoryAndroidTest.java
new file mode 100644
index 0000000000..e64dccc124
--- /dev/null
+++ b/retrofit/src/test/java/retrofit2/OptionalConverterFactoryAndroidTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 Square, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package retrofit2;
+
+import java.io.IOException;
+import java.util.Optional;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import retrofit2.helpers.ObjectInstanceConverterFactory;
+import retrofit2.http.GET;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.robolectric.annotation.Config.NEWEST_SDK;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(sdk = NEWEST_SDK)
+public final class OptionalConverterFactoryAndroidTest {
+ interface Service {
+ @GET("/") Call> optional();
+ @GET("/") Call