Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianming11 committed Jan 4, 2021
2 parents 4ba44ed + 2c9bd25 commit 38d7095
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ retrofit:
- [Wire](https://github.com/square/wire): com.squareup.Retrofit:converter-wire
- [Simple XML](http://simple.sourceforge.net/): com.squareup.Retrofit:converter-simplexml
- [JAXB](https://docs.oracle.com/javase/tutorial/jaxb/intro/index.html): com.squareup.retrofit2:converter-jaxb
- fastJson:com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory

`retrofit-spring-boot-starter`支持通过`retrofit.global-converter-factories`配置全局数据转换器工厂,转换器工厂实例优先从Spring容器获取,如果没有获取到,则反射创建。默认的全局数据转换器工厂是`retrofit2.converter.jackson.JacksonConverterFactory`,你可以直接通过`spring.jackson.*`配置`jackson`序列化规则,配置可参考[Customize the Jackson ObjectMapper](https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/htmlsingle/#howto-customize-the-jackson-objectmapper)!

Expand Down
1 change: 1 addition & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ For each Java interface, you can also specify the `CallAdapter.Factory` used by
- [Wire](https://github.com/square/wire): com.squareup.Retrofit:converter-wire
- [Simple XML](http://simple.sourceforge.net/): com.squareup.Retrofit:converter-simplexml
- [JAXB](https://docs.oracle.com/javase/tutorial/jaxb/intro/index.html): com.squareup.retrofit2:converter-jaxb
- fastJson:com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory

`retrofit-spring-boot-starter` supports configuring the global `converter factory` through `retrofit.global-converter-factories`. The converter factory instance is first obtained from the Spring container. If it is not obtained, it is created by reflection. The default global data converter factory is `retrofit2.converter.jackson.JacksonConverterFactory`, you can directly configure the `jackson` serialization rules through `spring.jackson.*`, please refer to [Customize the Jackson ObjectMapper](https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/htmlsingle/#howto-customize-the-jackson-objectmapper)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.lianjiatech.retrofit.spring.boot.test;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.lianjiatech.retrofit.spring.boot.test.entity.Person;
Expand Down Expand Up @@ -304,5 +305,25 @@ public void testNoBaseUrl() throws IOException {

}

@Test
public void testMap() throws IOException {

Map<String, Map<String, String>> map = new HashMap<>(4);
Map<String, String> test = new HashMap<>(4);
test.put("a", "aa");
test.put("b", "bb");
map.put("test", test);

MockResponse response = new MockResponse()
.setResponseCode(200)
.addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody(objectMapper.writeValueAsString(map));
server.enqueue(response);

Map<String, Map<String, String>> stringMapMap = httpApi2.testMap();
System.out.println(stringMapMap);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import retrofit2.http.GET;
import retrofit2.http.Query;

import java.util.Map;

/**
* @author 陈添明
*/
Expand All @@ -26,4 +28,8 @@ public interface HttpApi2 {
*/
@GET("person")
Result<Person> getPerson(@Query("id") Long id);


@GET("testMap")
Map<String, Map<String, String>> testMap();
}

0 comments on commit 38d7095

Please sign in to comment.