diff --git a/README.md b/README.md index a6908e5..29c2392 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter] com.github.lianjiatech retrofit-spring-boot-starter - 2.3.5 + 2.3.6 ``` @@ -60,7 +60,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter] com.github.lianjiatech retrofit-spring-boot-starter - 2.3.5 + 2.3.6 com.squareup.okhttp3 @@ -148,8 +148,9 @@ public class TestService { ```yaml retrofit: - # 全局转换器工厂(组件扩展的转换器工厂已经内置,这里请勿重复配置) + # 全局转换器工厂 global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory - retrofit2.converter.jackson.JacksonConverterFactory # 全局调用适配器工厂(组件扩展的调用适配器工厂已经内置,这里请勿重复配置) global-call-adapter-factories: @@ -775,8 +776,9 @@ retrofit: ```yaml retrofit: - # 全局转换器工厂(组件扩展的转换器工厂已经内置,这里请勿重复配置) + # 全局转换器工厂 global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory - retrofit2.converter.jackson.JacksonConverterFactory ``` diff --git a/README_EN.md b/README_EN.md index 21275f7..dcb25a1 100644 --- a/README_EN.md +++ b/README_EN.md @@ -37,7 +37,7 @@ com.github.lianjiatech retrofit-spring-boot-starter - 2.3.5 + 2.3.6 ``` @@ -47,7 +47,7 @@ com.github.lianjiatech retrofit-spring-boot-starter - 2.3.5 + 2.3.6 com.squareup.okhttp3 @@ -137,6 +137,7 @@ The component supports multiple configurable properties to deal with different b ```yaml retrofit: global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory - retrofit2.converter.jackson.JacksonConverterFactory global-call-adapter-factories: global-log: @@ -721,8 +722,8 @@ If you need to modify the `Jackson` configuration, you can override the `bean` c ```yaml retrofit: - # The `Converter.Factory` of the component extension has been built in, please do not repeat the configuration here global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory - retrofit2.converter.jackson.JacksonConverterFactory ``` diff --git a/pom.xml b/pom.xml index f044f7f..d77cdd1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.lianjiatech retrofit-spring-boot-starter - 2.3.5 + 2.3.6 retrofit-spring-boot-starter retrofit-spring-boot-starter diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitAutoConfiguration.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitAutoConfiguration.java index 0e7ac31..6a230de 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitAutoConfiguration.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitAutoConfiguration.java @@ -2,6 +2,7 @@ import java.util.List; +import com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -60,6 +61,11 @@ public static PathMatchInterceptorBdfProcessor prototypeInterceptorBdfProcessor( } } + @Bean + public BasicTypeConverterFactory basicTypeConverterFactory() { + return BasicTypeConverterFactory.INSTANCE; + } + @Bean @ConditionalOnMissingBean public SourceOkHttpClientRegistry sourceOkHttpClientRegistry( diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitProperties.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitProperties.java index 83096d7..9cc71dd 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitProperties.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/config/RetrofitProperties.java @@ -1,5 +1,6 @@ package com.github.lianjiatech.retrofit.spring.boot.config; +import com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -47,7 +48,8 @@ public class RetrofitProperties { */ @SuppressWarnings("unchecked") private Class[] globalConverterFactories = - (Class[])new Class[] {JacksonConverterFactory.class}; + (Class[])new Class[] {BasicTypeConverterFactory.class, + JacksonConverterFactory.class}; /** * 全局调用适配器工厂,转换器实例优先从Spring容器获取,如果没有获取到,则反射创建。 diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java index 579005b..685439d 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java @@ -171,7 +171,6 @@ private Retrofit createRetrofit() { retrofitBuilder.addCallAdapterFactory(ResponseCallAdapterFactory.INSTANCE); retrofitBuilder.addCallAdapterFactory(BodyCallAdapterFactory.INSTANCE); - retrofitBuilder.addConverterFactory(BasicTypeConverterFactory.INSTANCE); combineAndCreate(retrofitClient.converterFactories(), retrofitConfigBean.getGlobalConverterFactoryClasses()) .forEach(retrofitBuilder::addConverterFactory); @@ -182,7 +181,7 @@ private void addReactiveCallAdapterFactory(Retrofit.Builder retrofitBuilder) { if (reactor3ClassExist()) { retrofitBuilder.addCallAdapterFactory(MonoCallAdapterFactory.INSTANCE); } - if (rxjava2CalssExist()) { + if (rxjava2ClassExist()) { retrofitBuilder.addCallAdapterFactory(Rxjava2SingleCallAdapterFactory.INSTANCE); retrofitBuilder.addCallAdapterFactory(Rxjava2CompletableCallAdapterFactory.INSTANCE); } @@ -201,7 +200,7 @@ private boolean rxjava3ClassExist() { } } - private boolean rxjava2CalssExist() { + private boolean rxjava2ClassExist() { try { Class.forName("io.reactivex.Single"); return true; diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java index 0c971fc..53c5078 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java @@ -57,12 +57,6 @@ public class RetrofitStarterTest { @Autowired private HttpApi3 httpApi3; - @Autowired - private InterceptApi interceptApi; - - @Autowired - private DownloadApi downloadApi; - private static final ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setSerializationInclusion(JsonInclude.Include.NON_NULL); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 81982a2..ec4bc4e 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -1,7 +1,8 @@ retrofit: - # 全局转换器工厂(组件扩展的转换器工厂已经内置,这里请勿重复配置) + # 全局转换器工厂 global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory - retrofit2.converter.jackson.JacksonConverterFactory # 全局调用适配器工厂(组件扩展的调用适配器工厂已经内置,这里请勿重复配置) global-call-adapter-factories: