Skip to content

Commit

Permalink
fix BasicTypeConverterFactory priority bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianming11 committed Jul 4, 2022
1 parent ed36be4 commit 2bd57b8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -49,7 +49,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter]
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>2.3.5</version>
<version>2.3.6</version>
</dependency>
```

Expand All @@ -60,7 +60,7 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter]
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>2.3.5</version>
<version>2.3.6</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -775,8 +776,9 @@ retrofit:

```yaml
retrofit:
# 全局转换器工厂(组件扩展的转换器工厂已经内置,这里请勿重复配置)
# 全局转换器工厂
global-converter-factories:
- com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory
- retrofit2.converter.jackson.JacksonConverterFactory
```

Expand Down
7 changes: 4 additions & 3 deletions README_EN.md
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>2.3.5</version>
<version>2.3.6</version>
</dependency>
```

Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>2.3.5</version>
<version>2.3.6</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>2.3.5</version>
<version>2.3.6</version>

<name>retrofit-spring-boot-starter</name>
<description>retrofit-spring-boot-starter</description>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +61,11 @@ public static PathMatchInterceptorBdfProcessor prototypeInterceptorBdfProcessor(
}
}

@Bean
public BasicTypeConverterFactory basicTypeConverterFactory() {
return BasicTypeConverterFactory.INSTANCE;
}

@Bean
@ConditionalOnMissingBean
public SourceOkHttpClientRegistry sourceOkHttpClientRegistry(
Expand Down
@@ -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;

Expand Down Expand Up @@ -47,7 +48,8 @@ public class RetrofitProperties {
*/
@SuppressWarnings("unchecked")
private Class<? extends Converter.Factory>[] globalConverterFactories =
(Class<? extends Converter.Factory>[])new Class[] {JacksonConverterFactory.class};
(Class<? extends Converter.Factory>[])new Class[] {BasicTypeConverterFactory.class,
JacksonConverterFactory.class};

/**
* 全局调用适配器工厂,转换器实例优先从Spring容器获取,如果没有获取到,则反射创建。
Expand Down
Expand Up @@ -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);

Expand All @@ -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);
}
Expand All @@ -201,7 +200,7 @@ private boolean rxjava3ClassExist() {
}
}

private boolean rxjava2CalssExist() {
private boolean rxjava2ClassExist() {
try {
Class.forName("io.reactivex.Single");
return true;
Expand Down
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion 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:
Expand Down

0 comments on commit 2bd57b8

Please sign in to comment.