1313
1414package org .openapitools .client ;
1515
16+
1617import com .fasterxml .jackson .core .JsonProcessingException ;
1718import com .fasterxml .jackson .databind .DeserializationFeature ;
1819import com .fasterxml .jackson .databind .ObjectMapper ;
1920import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
21+ import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
22+
23+
2024import java .util .function .Consumer ;
2125import org .openapitools .jackson .nullable .JsonNullableModule ;
2226import org .springframework .core .ParameterizedTypeReference ;
2529import org .springframework .http .InvalidMediaTypeException ;
2630import org .springframework .http .MediaType ;
2731import org .springframework .http .converter .HttpMessageConverter ;
28- import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
2932import org .springframework .util .CollectionUtils ;
3033import org .springframework .util .LinkedMultiValueMap ;
3134import 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