From ef8fe30a0d8e6e33499fc4ecd71732ef38ea2cf2 Mon Sep 17 00:00:00 2001 From: Tomasz Letachowicz Date: Sun, 6 Oct 2024 23:14:14 +0200 Subject: [PATCH] Fix java rest client's ApiClient constructors to make sure objectMapper parameter is used in the client (#19667) --- .../libraries/restclient/ApiClient.mustache | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache index 8af468cfb4cf..43d97e14f196 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache @@ -87,29 +87,26 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() {