@@ -16,7 +16,12 @@ import tools.jackson.databind.json.JsonMapper;
1616{ {/useJackson3} }
1717import java.time.OffsetDateTime;
1818import { {jacksonPackage} }.core.type.TypeReference;
19- import { {jacksonPackage} }.core.JsonProcessingException;
19+ { {^useJackson3} }
20+ import com.fasterxml.jackson.core.JsonProcessingException;
21+ { {/useJackson3} }
22+ { {#useJackson3} }
23+ import tools.jackson.core.JacksonException;
24+ { {/useJackson3} }
2025{ {#openApiNullable} }
2126{ {^useJackson3} }
2227import org.openapitools.jackson.nullable.JsonNullableModule;
@@ -576,7 +581,16 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
576581 public ApiClient setDateFormat(DateFormat dateFormat) {
577582 this.dateFormat = dateFormat;
578583 // Also set the date format for model (de)serialization with Date properties.
584+ {{^useJackson3} }
579585 this.objectMapper.setDateFormat((DateFormat) dateFormat.clone());
586+ { {/useJackson3} }
587+ { {#useJackson3} }
588+ if (this.objectMapper instanceof JsonMapper) {
589+ this.objectMapper = ((JsonMapper) this.objectMapper).rebuild().defaultDateFormat((DateFormat) dateFormat.clone()).build();
590+ } else {
591+ throw new UnsupportedOperationException(" setDateFormat is only supported when objectMapper is a JsonMapper instance" );
592+ }
593+ { {/useJackson3} }
580594 return this;
581595 }
582596
@@ -826,7 +840,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
826840 if (isJsonMime(mimeType)) {
827841 try {
828842 return new StringEntity(objectMapper.writeValueAsString(obj), contentType.withCharset(StandardCharsets.UTF_8));
829- } catch (JsonProcessingException e) {
843+ } catch ({ {^useJackson3 } } JsonProcessingException{ {/useJackson3 } } { {#useJackson3 } }JacksonException { {/useJackson3 } } e) {
830844 throw new ApiException(e);
831845 }
832846 } else if (mimeType.equals(ContentType.MULTIPART_FORM_DATA.getMimeType())) {
0 commit comments