From 3690cb78d84a0e6b129be61f529d8dcc4bcb7841 Mon Sep 17 00:00:00 2001 From: chentianming Date: Wed, 30 Dec 2020 20:36:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Map>=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/boot/test/RetrofitStarterTest.java | 21 +++++++++++++++++++ .../spring/boot/test/http/HttpApi2.java | 6 ++++++ 2 files changed, 27 insertions(+) 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 316ef14..1af48e1 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 @@ -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; @@ -304,5 +305,25 @@ public void testNoBaseUrl() throws IOException { } + @Test + public void testMap() throws IOException { + + Map> map = new HashMap<>(4); + Map 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> stringMapMap = httpApi2.testMap(); + System.out.println(stringMapMap); + } + } diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/HttpApi2.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/HttpApi2.java index 160bcb3..326d31a 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/HttpApi2.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/HttpApi2.java @@ -10,6 +10,8 @@ import retrofit2.http.GET; import retrofit2.http.Query; +import java.util.Map; + /** * @author 陈添明 */ @@ -26,4 +28,8 @@ public interface HttpApi2 { */ @GET("person") Result getPerson(@Query("id") Long id); + + + @GET("testMap") + Map> testMap(); } From 2c9bd25445166d57805add72b0f6aa33b6364cfb Mon Sep 17 00:00:00 2001 From: chentianming Date: Mon, 4 Jan 2021 17:49:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=8A=A0fastJson?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + README_EN.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 6184ebe..d0df745 100644 --- a/README.md +++ b/README.md @@ -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)! diff --git a/README_EN.md b/README_EN.md index 1fd88d7..e5aaec6 100644 --- a/README_EN.md +++ b/README_EN.md @@ -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)