[java][webclient] Register Jackson modules on ObjectMapper (#911)

* [java][webclient] register jackson modules on object mapper

* Regenerate client

* Removed findAndRegisterModules() call

* ObjectMapper is initialized only if NOT provided by client

* Remove (now) useless DateFormat inside buildWebClient signature and regenerate client
This commit is contained in:
Marco 2019-01-05 11:29:49 +01:00 committed by William Cheng
parent fa9bd1f567
commit b931da2909
2 changed files with 20 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package {{invokerPackage}};
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.ParameterizedTypeReference;
@ -88,16 +89,21 @@ public class ApiClient {
public ApiClient() {
this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(dateFormat);
mapper.registerModule(new JavaTimeModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.webClient = buildWebClient(mapper);
this.init();
}
public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format);
this(buildWebClient(mapper.copy()), format);
}
public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy())), format);
}
private ApiClient(WebClient webClient, DateFormat format) {
@ -126,9 +132,7 @@ public class ApiClient {
* Build the RestTemplate used to make HTTP requests.
* @return RestTemplate
*/
public static WebClient buildWebClient(ObjectMapper mapper, DateFormat dateFormat) {
mapper.setDateFormat(dateFormat);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
public static WebClient buildWebClient(ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(clientDefaultCodecsConfigurer -> {

View File

@ -2,6 +2,7 @@ package org.openapitools.client;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.ParameterizedTypeReference;
@ -88,16 +89,21 @@ public class ApiClient {
public ApiClient() {
this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(dateFormat);
mapper.registerModule(new JavaTimeModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.webClient = buildWebClient(mapper);
this.init();
}
public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format);
this(buildWebClient(mapper.copy()), format);
}
public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy())), format);
}
private ApiClient(WebClient webClient, DateFormat format) {
@ -127,9 +133,7 @@ public class ApiClient {
* Build the RestTemplate used to make HTTP requests.
* @return RestTemplate
*/
public static WebClient buildWebClient(ObjectMapper mapper, DateFormat dateFormat) {
mapper.setDateFormat(dateFormat);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
public static WebClient buildWebClient(ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(clientDefaultCodecsConfigurer -> {