diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache index 7f91fe44134..ed2dac7fa8c 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache @@ -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 -> { diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java index 7d5f7dd66bb..e8634916ba7 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java @@ -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 -> {