瀏覽代碼

扩展core-retrofit,增加转换器兼容直接返回string等基本类型的接口定义

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 3 年之前
父節點
當前提交
b4de19860b

+ 4 - 0
core-retrofit/pom.xml

@@ -48,6 +48,10 @@
             <groupId>com.squareup.retrofit2</groupId>
             <artifactId>converter-jackson</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>converter-scalars</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.squareup.okhttp3</groupId>
             <artifactId>okhttp</artifactId>

+ 2 - 0
core-retrofit/src/main/java/com/qmth/boot/core/retrofit/core/RetrofitFactoryBean.java

@@ -17,6 +17,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import retrofit2.Retrofit;
 import retrofit2.converter.jackson.JacksonConverterFactory;
+import retrofit2.converter.scalars.ScalarsConverterFactory;
 
 import java.lang.reflect.Proxy;
 
@@ -58,6 +59,7 @@ public class RetrofitFactoryBean<T> implements FactoryBean<T>, ApplicationContex
 
         OkHttpClient client = getOkHttpClient(retrofitClient, customize);
         Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl(getBaseUrl(retrofitClient, customize))
+                .addConverterFactory(ScalarsConverterFactory.create())
                 .addConverterFactory(JacksonConverterFactory.create()).validateEagerly(true).client(client);
         if (retrofitClient.directReturn()) {
             retrofitBuilder.addCallAdapterFactory(new DirectCallAdapterFactory());

+ 6 - 0
pom.xml

@@ -285,6 +285,12 @@
                 <artifactId>retrofit</artifactId>
                 <version>2.9.0</version>
             </dependency>
+            <!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-scalars -->
+            <dependency>
+                <groupId>com.squareup.retrofit2</groupId>
+                <artifactId>converter-scalars</artifactId>
+                <version>2.9.0</version>
+            </dependency>
             <!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-jackson -->
             <dependency>
                 <groupId>com.squareup.retrofit2</groupId>