Skip to content

Commit 2c365f9

Browse files
committed
Update restclient
1 parent a0fe080 commit 2c365f9

16 files changed

Lines changed: 305 additions & 353 deletions

File tree

samples/client/echo_api/java/restclient/pom.xml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<plugin>
3737
<groupId>org.apache.maven.plugins</groupId>
3838
<artifactId>maven-enforcer-plugin</artifactId>
39-
<version>3.4.0</version>
39+
<version>3.6.2</version>
4040
<executions>
4141
<execution>
4242
<id>enforce-maven</id>
@@ -56,7 +56,7 @@
5656
<plugin>
5757
<groupId>org.apache.maven.plugins</groupId>
5858
<artifactId>maven-surefire-plugin</artifactId>
59-
<version>3.1.2</version>
59+
<version>3.5.4</version>
6060
<configuration>
6161
<systemPropertyVariables>
6262
<property>
@@ -69,14 +69,6 @@
6969
<reuseForks>false</reuseForks>
7070
<useUnlimitedThreads>true</useUnlimitedThreads>
7171
</configuration>
72-
<dependencies>
73-
<!--Custom provider and engine for Junit 5 to surefire-->
74-
<dependency>
75-
<groupId>org.junit.jupiter</groupId>
76-
<artifactId>junit-jupiter-engine</artifactId>
77-
<version>${junit-version}</version>
78-
</dependency>
79-
</dependencies>
8072
</plugin>
8173
<plugin>
8274
<artifactId>maven-dependency-plugin</artifactId>
@@ -97,7 +89,7 @@
9789
<plugin>
9890
<groupId>org.apache.maven.plugins</groupId>
9991
<artifactId>maven-jar-plugin</artifactId>
100-
<version>3.3.0</version>
92+
<version>3.5.0</version>
10193
<executions>
10294
<execution>
10395
<goals>
@@ -112,7 +104,7 @@
112104
<plugin>
113105
<groupId>org.codehaus.mojo</groupId>
114106
<artifactId>build-helper-maven-plugin</artifactId>
115-
<version>3.4.0</version>
107+
<version>3.6.1</version>
116108
<executions>
117109
<execution>
118110
<id>add_sources</id>
@@ -143,7 +135,7 @@
143135
<plugin>
144136
<groupId>org.apache.maven.plugins</groupId>
145137
<artifactId>maven-compiler-plugin</artifactId>
146-
<version>3.11.0</version>
138+
<version>3.15.0</version>
147139
<configuration>
148140
<source>17</source>
149141
<target>17</target>
@@ -152,7 +144,7 @@
152144
<plugin>
153145
<groupId>org.apache.maven.plugins</groupId>
154146
<artifactId>maven-javadoc-plugin</artifactId>
155-
<version>3.5.0</version>
147+
<version>3.12.0</version>
156148
<configuration>
157149
<doclint>none</doclint>
158150
</configuration>
@@ -168,7 +160,7 @@
168160
<plugin>
169161
<groupId>org.apache.maven.plugins</groupId>
170162
<artifactId>maven-source-plugin</artifactId>
171-
<version>3.3.0</version>
163+
<version>3.4.0</version>
172164
<executions>
173165
<execution>
174166
<id>attach-sources</id>
@@ -189,7 +181,7 @@
189181
<plugin>
190182
<groupId>org.apache.maven.plugins</groupId>
191183
<artifactId>maven-gpg-plugin</artifactId>
192-
<version>1.5</version>
184+
<version>3.2.8</version>
193185
<executions>
194186
<execution>
195187
<id>sign-artifacts</id>
@@ -207,13 +199,6 @@
207199

208200
<dependencies>
209201

210-
<!-- @Nullable annotation -->
211-
<dependency>
212-
<groupId>com.google.code.findbugs</groupId>
213-
<artifactId>jsr305</artifactId>
214-
<version>3.0.2</version>
215-
</dependency>
216-
217202
<!-- HTTP client: Spring RestClient -->
218203
<dependency>
219204
<groupId>org.springframework</groupId>
@@ -235,12 +220,12 @@
235220
<dependency>
236221
<groupId>com.fasterxml.jackson.core</groupId>
237222
<artifactId>jackson-annotations</artifactId>
238-
<version>${jackson-version}</version>
223+
<version>${jackson-annotations-version}</version>
239224
</dependency>
240225
<dependency>
241226
<groupId>com.fasterxml.jackson.core</groupId>
242227
<artifactId>jackson-databind</artifactId>
243-
<version>${jackson-databind-version}</version>
228+
<version>${jackson-version}</version>
244229
</dependency>
245230
<dependency>
246231
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
@@ -252,11 +237,14 @@
252237
<artifactId>jackson-databind-nullable</artifactId>
253238
<version>${jackson-databind-nullable-version}</version>
254239
</dependency>
240+
255241
<dependency>
256242
<groupId>com.fasterxml.jackson.datatype</groupId>
257243
<artifactId>jackson-datatype-jsr310</artifactId>
258244
<version>${jackson-version}</version>
259245
</dependency>
246+
247+
260248
<dependency>
261249
<groupId>jakarta.annotation</groupId>
262250
<artifactId>jakarta.annotation-api</artifactId>
@@ -274,12 +262,15 @@
274262
</dependencies>
275263
<properties>
276264
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
277-
<spring-web-version>6.1.21</spring-web-version>
278-
<jackson-version>2.19.2</jackson-version>
279-
<jackson-databind-version>2.19.2</jackson-databind-version>
280-
<jackson-databind-nullable-version>0.2.9</jackson-databind-nullable-version>
265+
266+
<spring-web-version>6.2.16</spring-web-version>
267+
<jackson-version>2.21.0</jackson-version>
281268
<jakarta-annotation-version>2.1.1</jakarta-annotation-version>
282-
<beanvalidation-version>3.0.2</beanvalidation-version>
283-
<junit-version>5.10.2</junit-version>
269+
270+
271+
<jackson-annotations-version>2.21</jackson-annotations-version>
272+
<jackson-databind-nullable-version>0.2.9</jackson-databind-nullable-version>
273+
<beanvalidation-version>3.1.1</beanvalidation-version>
274+
<junit-version>5.14.3</junit-version>
284275
</properties>
285276
</project>

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
package org.openapitools.client;
1515

16+
1617
import com.fasterxml.jackson.core.JsonProcessingException;
1718
import com.fasterxml.jackson.databind.DeserializationFeature;
1819
import com.fasterxml.jackson.databind.ObjectMapper;
1920
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21+
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
22+
23+
2024
import java.util.function.Consumer;
2125
import org.openapitools.jackson.nullable.JsonNullableModule;
2226
import org.springframework.core.ParameterizedTypeReference;
@@ -25,7 +29,6 @@
2529
import org.springframework.http.InvalidMediaTypeException;
2630
import org.springframework.http.MediaType;
2731
import org.springframework.http.converter.HttpMessageConverter;
28-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
2932
import org.springframework.util.CollectionUtils;
3033
import org.springframework.util.LinkedMultiValueMap;
3134
import org.springframework.util.MultiValueMap;
@@ -91,8 +94,7 @@ protected String collectionToString(Collection<?> collection) {
9194

9295
protected final RestClient restClient;
9396
protected final DateFormat dateFormat;
94-
protected final ObjectMapper objectMapper;
95-
97+
protected final ObjectMapper mapper;
9698
protected Map<String, Authentication> authentications;
9799

98100

@@ -109,14 +111,14 @@ public ApiClient(ObjectMapper mapper, DateFormat format) {
109111
}
110112

111113
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
112-
this.objectMapper = mapper.copy();
113-
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
114+
this.mapper = mapper.copy();
115+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.mapper));
114116
this.dateFormat = format;
115117
this.init();
116118
}
117119

118120
protected ApiClient(RestClient restClient, DateFormat format) {
119-
this(restClient, createDefaultObjectMapper(format), format);
121+
this(restClient, createDefaultMapper(format), format);
120122
}
121123

122124
public static DateFormat createDefaultDateFormat() {
@@ -125,7 +127,7 @@ public static DateFormat createDefaultDateFormat() {
125127
return dateFormat;
126128
}
127129

128-
public static ObjectMapper createDefaultObjectMapper(@Nullable DateFormat dateFormat) {
130+
public static ObjectMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
129131
if (null == dateFormat) {
130132
dateFormat = createDefaultDateFormat();
131133
}
@@ -153,6 +155,7 @@ protected void init() {
153155
* @return RestClient
154156
*/
155157
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
158+
156159
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
157160
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
158161
};
@@ -165,7 +168,7 @@ public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
165168
* @return RestClient
166169
*/
167170
public static RestClient.Builder buildRestClientBuilder() {
168-
return buildRestClientBuilder(createDefaultObjectMapper(null));
171+
return buildRestClientBuilder(createDefaultMapper(null));
169172
}
170173

171174
/**
@@ -182,7 +185,7 @@ public static RestClient buildRestClient(ObjectMapper mapper) {
182185
* @return RestClient
183186
*/
184187
public static RestClient buildRestClient() {
185-
return buildRestClientBuilder(createDefaultObjectMapper(null)).build();
188+
return buildRestClientBuilder(createDefaultMapper(null)).build();
186189
}
187190

188191
/**
@@ -399,10 +402,10 @@ public String formatDate(Date date) {
399402

400403
/**
401404
* Get the ObjectMapper used to make HTTP requests.
402-
* @return ObjectMapper objectMapper
405+
* @return ObjectMapper mapper
403406
*/
404407
public ObjectMapper getObjectMapper() {
405-
return objectMapper;
408+
return mapper;
406409
}
407410

408411
/**
@@ -452,7 +455,7 @@ public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionForm
452455
valueCollection = (Collection<?>) value;
453456
} else {
454457
try {
455-
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
458+
return parameterToMultiValueMap(collectionFormat, name, mapper.writeValueAsString(value));
456459
} catch (JsonProcessingException e) {
457460
throw new RuntimeException(e);
458461
}
@@ -461,7 +464,7 @@ public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionForm
461464
List<String> values = new ArrayList<>();
462465
for(Object o : valueCollection) {
463466
try {
464-
values.add(objectMapper.writeValueAsString(o));
467+
values.add(mapper.writeValueAsString(o));
465468
} catch (JsonProcessingException e) {
466469
throw new RuntimeException(e);
467470
}

0 commit comments

Comments
 (0)