Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

{{#useJackson3}}
public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
{{#failOnUnknownProperties}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

{{#useJackson3}}
public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
{{#failOnUnknownProperties}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3671,6 +3671,37 @@ public void testRestClientWithXMLAndJackson3AndOpenApiNullable_issue_23860() {
);
}

@Test(description = "Regression test for issue #24588: with useJackson3=true the generated"
+ " createDefaultMapper must fall back to createDefaultDateFormat() when called with"
+ " null, like the Jackson 2 branch does. Otherwise date-time fields serialize as"
+ " epoch numbers instead of RFC 3339.")
public void testJackson3DefaultMapperFallsBackToDefaultDateFormat_issue_24588() {
for (String library : new String[]{JavaClientCodegen.RESTCLIENT, JavaClientCodegen.WEBCLIENT}) {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName(JAVA_GENERATOR)
.setLibrary(library)
.setAdditionalProperties(Map.of(
CodegenConstants.API_PACKAGE, "xyz.abcdef.api",
JavaClientCodegen.USE_JACKSON_3, true,
JavaClientCodegen.USE_SPRING_BOOT4, true,
JavaClientCodegen.OPENAPI_NULLABLE, false
))
.setInputSpec("src/test/resources/3_1/java/petstore.yaml")
.setOutputDir(output.toString().replace("\\", "/"));

List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

validateJavaSourceFiles(files);
assertFileContains(
output.resolve("src/main/java/xyz/abcdef/ApiClient.java"),
"public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {",
"if (null == dateFormat) {",
"dateFormat = createDefaultDateFormat();"
);
}
}


@Test
public void testRestClientWithUseSingleRequestParameter_issue_19406() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public static DateFormat createDefaultDateFormat() {
}

public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public static DateFormat createDefaultDateFormat() {
}

public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public static DateFormat createDefaultDateFormat() {
}

public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
import org.openapitools.client.auth.OAuth;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.25.0-SNAPSHOT")
public class ApiClient extends JavaTimeFormatter {

Check warning on line 84 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no comment
public enum CollectionFormat {

Check warning on line 85 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no comment
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);

protected final String separator;
Expand All @@ -100,13 +100,13 @@
protected HttpHeaders defaultHeaders = new HttpHeaders();
protected MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<String, String>();

protected String basePath = "http://petstore.swagger.io/v2";

Check warning on line 103 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no comment

protected final WebClient webClient;
protected final DateFormat dateFormat;
protected final JsonMapper mapper;

protected Map<String, Authentication> authentications;

Check warning on line 109 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no comment

/**
* The {@link ExceptionProvider} used to create exceptions thrown by this client.
Expand Down Expand Up @@ -149,6 +149,9 @@
}

public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
if (null == dateFormat) {
dateFormat = createDefaultDateFormat();
}
return JsonMapper.builder()
.defaultDateFormat(dateFormat)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down Expand Up @@ -392,7 +395,7 @@
/**
* Parse the given string into Date object.
*/
public Date parseDate(String str) {

Check warning on line 398 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

Check warning on line 398 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no @param for str
try {
return dateFormat.parse(str);
} catch (ParseException e) {
Expand All @@ -403,7 +406,7 @@
/**
* Format the given Date object into string.
*/
public String formatDate(Date date) {

Check warning on line 409 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

Check warning on line 409 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no @param for date
return dateFormat.format(date);
}

Expand Down Expand Up @@ -667,7 +670,7 @@
* @param returnType The return type into which to deserialize the response
* @return The response body in chosen type
*/
public <T> ResponseSpec invokeAPI(String path, HttpMethod method, Map<String, Object> pathParams, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams, MultiValueMap<String, Object> formParams, List<MediaType> accept, MediaType contentType, String[] authNames, ParameterizedTypeReference<T> returnType) throws RestClientException {

Check warning on line 673 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

no @param for cookieParams
final WebClient.RequestBodySpec requestBuilder = prepareRequest(path, method, pathParams, queryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames);
return requestBuilder.retrieve();
}
Expand All @@ -678,7 +681,7 @@
* @param uriParams The path parameters
* return templatized query string
*/
protected String generateQueryUri(MultiValueMap<String, String> queryParams, Map<String, Object> uriParams) {

Check warning on line 684 in samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java

View workflow job for this annotation

GitHub Actions / Build Java Client JDK17 (samples/client/petstore/java/webclient-springBoot4-jackson3)

StringBuilder queryBuilder = new StringBuilder();
queryParams.forEach((name, values) -> {
if (CollectionUtils.isEmpty(values)) {
Expand Down
Loading