diff --git a/.github/workflows/samples-java-client-jdk17.yaml b/.github/workflows/samples-java-client-jdk17.yaml
index 64cc6432b09d..d4ba1d51a5d1 100644
--- a/.github/workflows/samples-java-client-jdk17.yaml
+++ b/.github/workflows/samples-java-client-jdk17.yaml
@@ -7,6 +7,7 @@ on:
- samples/client/petstore/java/resttemplate-springBoot4-*/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/restclient-*/**
+ - samples/client/petstore/java/native-jackson3/**
- samples/client/others/java/webclient-sealedInterface/**
- samples/client/others/java/webclient-sealedInterface_3_1/**
- samples/client/petstore/java/webclient-useSingleRequestParameter/**
@@ -17,6 +18,7 @@ on:
- samples/client/petstore/java/resttemplate-springBoot4-*/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/restclient-*/**
+ - samples/client/petstore/java/native-jackson3/**
- samples/client/others/java/webclient-sealedInterface/**
- samples/client/others/java/webclient-sealedInterface_3_1/**
- samples/client/petstore/java/webclient-useSingleRequestParameter/**
@@ -41,6 +43,7 @@ jobs:
- samples/client/petstore/java/restclient-swagger2
- samples/client/petstore/java/restclient-useSingleRequestParameter
- samples/client/petstore/java/restclient-useSingleRequestParameter-static
+ - samples/client/petstore/java/native-jackson3
- samples/client/others/java/webclient-sealedInterface
- samples/client/others/java/webclient-sealedInterface_3_1
- samples/client/petstore/java/webclient-springBoot4-jackson3
diff --git a/bin/configs/java-native-jackson3.yaml b/bin/configs/java-native-jackson3.yaml
new file mode 100644
index 000000000000..2be924aa84d4
--- /dev/null
+++ b/bin/configs/java-native-jackson3.yaml
@@ -0,0 +1,12 @@
+generatorName: java
+outputDir: samples/client/petstore/java/native-jackson3
+library: native
+inputSpec: modules/openapi-generator/src/test/resources/3_0/java/native/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
+templateDir: modules/openapi-generator/src/main/resources/Java
+additionalProperties:
+ artifactId: petstore-native-jackson3
+ hideGenerationTimestamp: "true"
+ generateBuilders: true
+ useReflectionEqualsHashCode: "true"
+ useJackson3: "true"
+ openApiNullable: "false"
diff --git a/docs/generators/java-microprofile.md b/docs/generators/java-microprofile.md
index 9f52f695f462..6cc849ee61df 100644
--- a/docs/generators/java-microprofile.md
+++ b/docs/generators/java-microprofile.md
@@ -64,7 +64,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|invokerPackage|root package for generated code| |org.openapitools.client|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|
- **true**
- The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
- **false**
- The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true|
-|library|library template (sub-template) to use|- **jersey2**
- HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1
- **jersey3**
- HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1
- **feign**
- HTTP client: OpenFeign 13.2.1. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **feign-hc5**
- HTTP client: OpenFeign 13.2.1/HttpClient5 5.4.2. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **okhttp-gson**
- [DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
- **retrofit2**
- HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
- **resttemplate**
- HTTP client: Spring RestTemplate 5.3.33 (6.2.x if `useJakartaEe=true`, 7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.x (3.x if `useJackson3=true`)
- **webclient**
- HTTP client: Spring WebClient 5.1.18. JSON processing: Jackson 2.17.1
- **restclient**
- HTTP client: Spring RestClient 6.1.6. JSON processing: Jackson 2.17.1
- **resteasy**
- HTTP client: Resteasy client 4.7.6. JSON processing: Jackson 2.17.1
- **vertx**
- HTTP client: VertX client 3.5.2. JSON processing: Jackson 2.17.1
- **google-api-client**
- HTTP client: Google API client 2.2.0. JSON processing: Jackson 2.17.1
- **rest-assured**
- HTTP client: rest-assured 5.3.2. JSON processing: Gson 2.10.1 or Jackson 2.17.1. Only for Java 8
- **native**
- HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1. Only for Java11+
- **microprofile**
- HTTP client: Microprofile client 2.0 (default, set desired version via `microprofileRestClientVersion=x.x.x`). JSON processing: JSON-B 1.0.2 or Jackson 2.17.1
- **apache-httpclient**
- HTTP client: Apache httpclient 5.2.1. JSON processing: Jackson 2.17.1
|okhttp-gson|
+|library|library template (sub-template) to use|- **jersey2**
- HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1
- **jersey3**
- HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1
- **feign**
- HTTP client: OpenFeign 13.2.1. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **feign-hc5**
- HTTP client: OpenFeign 13.2.1/HttpClient5 5.4.2. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **okhttp-gson**
- [DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
- **retrofit2**
- HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
- **resttemplate**
- HTTP client: Spring RestTemplate 5.3.33 (6.2.x if `useJakartaEe=true`, 7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.x (3.x if `useJackson3=true`)
- **webclient**
- HTTP client: Spring WebClient 5.1.18 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)
- **restclient**
- HTTP client: Spring RestClient 6.1.6 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)
- **resteasy**
- HTTP client: Resteasy client 4.7.6. JSON processing: Jackson 2.17.1
- **vertx**
- HTTP client: VertX client 3.5.2. JSON processing: Jackson 2.17.1
- **google-api-client**
- HTTP client: Google API client 2.2.0. JSON processing: Jackson 2.17.1
- **rest-assured**
- HTTP client: rest-assured 5.3.2. JSON processing: Gson 2.10.1 or Jackson 2.17.1. Only for Java 8
- **native**
- HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`). Only for Java11+
- **microprofile**
- HTTP client: Microprofile client 2.0 (default, set desired version via `microprofileRestClientVersion=x.x.x`). JSON processing: JSON-B 1.0.2 or Jackson 2.17.1
- **apache-httpclient**
- HTTP client: Apache httpclient 5.2.1. JSON processing: Jackson 2.17.1
|okhttp-gson|
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null|
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useGzipFeature|Send gzip-encoded requests| |false|
-|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
+|useJackson3|Use Jackson 3 instead of Jackson 2. Supported for 'native' library (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true). Incompatible with 'openApiNullable'.| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
diff --git a/docs/generators/java.md b/docs/generators/java.md
index 2394ce329544..b37426133f6f 100644
--- a/docs/generators/java.md
+++ b/docs/generators/java.md
@@ -64,7 +64,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|invokerPackage|root package for generated code| |org.openapitools.client|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|- **true**
- The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
- **false**
- The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true|
-|library|library template (sub-template) to use|- **jersey2**
- HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1
- **jersey3**
- HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1
- **feign**
- HTTP client: OpenFeign 13.2.1. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **feign-hc5**
- HTTP client: OpenFeign 13.2.1/HttpClient5 5.4.2. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **okhttp-gson**
- [DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
- **retrofit2**
- HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
- **resttemplate**
- HTTP client: Spring RestTemplate 5.3.33 (6.2.x if `useJakartaEe=true`, 7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.x (3.x if `useJackson3=true`)
- **webclient**
- HTTP client: Spring WebClient 5.1.18. JSON processing: Jackson 2.17.1
- **restclient**
- HTTP client: Spring RestClient 6.1.6. JSON processing: Jackson 2.17.1
- **resteasy**
- HTTP client: Resteasy client 4.7.6. JSON processing: Jackson 2.17.1
- **vertx**
- HTTP client: VertX client 3.5.2. JSON processing: Jackson 2.17.1
- **google-api-client**
- HTTP client: Google API client 2.2.0. JSON processing: Jackson 2.17.1
- **rest-assured**
- HTTP client: rest-assured 5.3.2. JSON processing: Gson 2.10.1 or Jackson 2.17.1. Only for Java 8
- **native**
- HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1. Only for Java11+
- **microprofile**
- HTTP client: Microprofile client 2.0 (default, set desired version via `microprofileRestClientVersion=x.x.x`). JSON processing: JSON-B 1.0.2 or Jackson 2.17.1
- **apache-httpclient**
- HTTP client: Apache httpclient 5.2.1. JSON processing: Jackson 2.17.1
|okhttp-gson|
+|library|library template (sub-template) to use|- **jersey2**
- HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1
- **jersey3**
- HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1
- **feign**
- HTTP client: OpenFeign 13.2.1. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **feign-hc5**
- HTTP client: OpenFeign 13.2.1/HttpClient5 5.4.2. JSON processing: Jackson 2.17.1 or Gson 2.10.1
- **okhttp-gson**
- [DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
- **retrofit2**
- HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
- **resttemplate**
- HTTP client: Spring RestTemplate 5.3.33 (6.2.x if `useJakartaEe=true`, 7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.x (3.x if `useJackson3=true`)
- **webclient**
- HTTP client: Spring WebClient 5.1.18 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)
- **restclient**
- HTTP client: Spring RestClient 6.1.6 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)
- **resteasy**
- HTTP client: Resteasy client 4.7.6. JSON processing: Jackson 2.17.1
- **vertx**
- HTTP client: VertX client 3.5.2. JSON processing: Jackson 2.17.1
- **google-api-client**
- HTTP client: Google API client 2.2.0. JSON processing: Jackson 2.17.1
- **rest-assured**
- HTTP client: rest-assured 5.3.2. JSON processing: Gson 2.10.1 or Jackson 2.17.1. Only for Java 8
- **native**
- HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`). Only for Java11+
- **microprofile**
- HTTP client: Microprofile client 2.0 (default, set desired version via `microprofileRestClientVersion=x.x.x`). JSON processing: JSON-B 1.0.2 or Jackson 2.17.1
- **apache-httpclient**
- HTTP client: Apache httpclient 5.2.1. JSON processing: Jackson 2.17.1
|okhttp-gson|
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null|
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useGzipFeature|Send gzip-encoded requests| |false|
-|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
+|useJackson3|Use Jackson 3 instead of Jackson 2. Supported for 'native' library (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true). Incompatible with 'openApiNullable'.| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java
index 0a2b2f483631..159f848084e5 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java
@@ -108,6 +108,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String SUPPORT_VERTX_FUTURE = "supportVertxFuture";
public static final String USE_SEALED_ONE_OF_INTERFACES = "useSealedOneOfInterfaces";
public static final String USE_UNARY_INTERCEPTOR = "useUnaryInterceptor";
+ public static final String USE_JACKSON_3 = "useJackson3";
// Internal configurations
public static final String SINGLE_REQUEST_PARAMETER = "singleRequestParameter";
@@ -119,7 +120,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String SERIALIZATION_LIBRARY_JSONB = "jsonb";
public static final String USE_SPRING_BOOT4 = "useSpringBoot4";
- public static final String USE_JACKSON_3 = "useJackson3";
private static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
private static final String JACKSON3_PACKAGE = "tools.jackson";
private static final String JACKSON_PACKAGE = "jacksonPackage";
@@ -158,6 +158,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
@Setter protected boolean supportVertxFuture = false;
@Setter protected boolean useSealedOneOfInterfaces = false;
@Setter protected boolean useUnaryInterceptor = false;
+ @Getter @Setter protected boolean useJackson3 = false;
protected String authFolder;
/**
@@ -165,7 +166,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
*/
@Getter protected String serializationLibrary = null;
@Getter @Setter protected boolean useSpringBoot4 = false;
- @Getter @Setter protected boolean useJackson3 = false;
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
protected String rootJavaEEPackage;
protected Map mpRestClientVersions = new LinkedHashMap<>();
@@ -270,6 +270,7 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(SUPPORT_URL_QUERY, "Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries."));
cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive));
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
+ cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 instead of Jackson 2. Supported for 'native' library (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true). Incompatible with 'openApiNullable'.", this.useJackson3));
cliOptions.add(CliOption.newBoolean(SUPPORT_VERTX_FUTURE, "Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.", this.supportVertxFuture));
cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.", this.useSealedOneOfInterfaces));
cliOptions.add(CliOption.newBoolean(USE_UNARY_INTERCEPTOR, "If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption", this.useUnaryInterceptor));
@@ -281,13 +282,13 @@ public JavaClientCodegen() {
supportedLibraries.put(OKHTTP_GSON, "[DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)");
supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 5.3.33 (6.2.x if `useJakartaEe=true`, 7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.x (3.x if `useJackson3=true`)");
- supportedLibraries.put(WEBCLIENT, "HTTP client: Spring WebClient 5.1.18. JSON processing: Jackson 2.17.1");
- supportedLibraries.put(RESTCLIENT, "HTTP client: Spring RestClient 6.1.6. JSON processing: Jackson 2.17.1");
+ supportedLibraries.put(WEBCLIENT, "HTTP client: Spring WebClient 5.1.18 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)");
+ supportedLibraries.put(RESTCLIENT, "HTTP client: Spring RestClient 6.1.6 (7.x.x if `useSpringBoot4=true`). JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`)");
supportedLibraries.put(RESTEASY, "HTTP client: Resteasy client 4.7.6. JSON processing: Jackson 2.17.1");
supportedLibraries.put(VERTX, "HTTP client: VertX client 3.5.2. JSON processing: Jackson 2.17.1");
supportedLibraries.put(GOOGLE_API_CLIENT, "HTTP client: Google API client 2.2.0. JSON processing: Jackson 2.17.1");
supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured 5.3.2. JSON processing: Gson 2.10.1 or Jackson 2.17.1. Only for Java 8");
- supportedLibraries.put(NATIVE, "HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1. Only for Java11+");
+ supportedLibraries.put(NATIVE, "HTTP client: Java native HttpClient. JSON processing: Jackson 2.17.1 (3.x if `useJackson3=true`). Only for Java11+");
supportedLibraries.put(MICROPROFILE, "HTTP client: Microprofile client " + MICROPROFILE_REST_CLIENT_DEFAULT_VERSION + " (default, set desired version via `" + MICROPROFILE_REST_CLIENT_VERSION + "=x.x.x`). JSON processing: JSON-B 1.0.2 or Jackson 2.17.1");
supportedLibraries.put(APACHE, "HTTP client: Apache httpclient 5.2.1. JSON processing: Jackson 2.17.1");
@@ -307,7 +308,7 @@ public JavaClientCodegen() {
serializationLibrary.setEnum(serializationOptions);
cliOptions.add(serializationLibrary);
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x.", useSpringBoot4));
- cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Set it in order to use jackson 3 dependencies (only allowed when `" + USE_SPRING_BOOT4 + "` is set and incompatible with `" + OPENAPI_NULLABLE + "`).", useJackson3)); // Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
+ // Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
// inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values,
// and the discriminator mapping schemas in the OAS document.
this.setLegacyDiscriminatorBehavior(false);
@@ -378,11 +379,15 @@ public void processOpts() {
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);
- if (isUseJackson3() && !isUseSpringBoot4()) {
- throw new IllegalArgumentException("useJackson3 is only available with Spring Boot >= 4");
+ if (useJackson3 && (libRestClient || libRestTemplate || libWebClient) && !useSpringBoot4) {
+ throw new IllegalArgumentException("useJackson3 for the restclient, resttemplate, and webclient libraries requires useSpringBoot4=true");
+ } else if (useJackson3 && !libNative && !libRestClient && !libRestTemplate && !libWebClient) {
+ throw new IllegalArgumentException("useJackson3 is only supported for the 'native', 'restclient', 'resttemplate', and 'webclient' libraries. " +
+ "The Spring libraries also require useSpringBoot4=true.");
}
- if (isUseJackson3() && isOpenApiNullable()) {
- throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
+ if (useJackson3 && openApiNullable) {
+ throw new IllegalArgumentException("openApiNullable=true is not compatible with useJackson3=true " +
+ "(jackson-databind-nullable has no Jackson 3 release). Please set openApiNullable=false explicitly.");
}
if (this.useJackson3) {
@@ -819,7 +824,7 @@ public void processOpts() {
additionalProperties.remove(SERIALIZATION_LIBRARY_GSON);
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
- if (!useJackson3) {
+ if (!useJackson3 || libNative || libRestTemplate || libWebClient) {
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
}
@@ -1066,7 +1071,9 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
model.imports.add("JsonProperty");
model.imports.add("JsonValue");
model.imports.add("JsonInclude");
- model.imports.add("JsonTypeName");
+ if (!useJackson3) {
+ model.imports.add("JsonTypeName");
+ }
}
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_GSON)) {
model.imports.add("SerializedName");
diff --git a/modules/openapi-generator/src/main/resources/Java/RFC3339DateFormat.mustache b/modules/openapi-generator/src/main/resources/Java/RFC3339DateFormat.mustache
index cb8ef4cf4f93..f18474dbb84c 100644
--- a/modules/openapi-generator/src/main/resources/Java/RFC3339DateFormat.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/RFC3339DateFormat.mustache
@@ -1,8 +1,6 @@
{{>licenseInfo}}
package {{invokerPackage}};
-import {{jacksonPackage}}.databind.util.StdDateFormat;
-
import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
@@ -10,6 +8,7 @@ import java.util.Date;
import java.text.DecimalFormat;
import java.util.GregorianCalendar;
import java.util.TimeZone;
+import {{jacksonPackage}}.databind.util.StdDateFormat;
{{>generatedAnnotation}}
diff --git a/modules/openapi-generator/src/main/resources/Java/RFC3339InstantDeserializer.mustache b/modules/openapi-generator/src/main/resources/Java/RFC3339InstantDeserializer.mustache
index ea4b0799a7de..4a7e5b8f7af9 100644
--- a/modules/openapi-generator/src/main/resources/Java/RFC3339InstantDeserializer.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/RFC3339InstantDeserializer.mustache
@@ -1,7 +1,9 @@
{{>licenseInfo}}
package {{invokerPackage}};
+{{^useJackson3}}
import java.io.IOException;
+{{/useJackson3}}
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
@@ -12,18 +14,34 @@ import java.time.temporal.TemporalAccessor;
import java.util.function.BiFunction;
import java.util.function.Function;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
+{{#useJackson3}}
+import tools.jackson.core.JacksonException;
+{{/useJackson3}}
+import {{jacksonPackage}}.core.JsonParser;
+import {{jacksonPackage}}.databind.DeserializationContext;
+{{^useJackson3}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature;
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.databind.cfg.DateTimeFeature;
+import tools.jackson.databind.ext.javatime.deser.InstantDeserializer;
+{{/useJackson3}}
{{>generatedAnnotation}}
public class RFC3339InstantDeserializer extends InstantDeserializer {
private static final long serialVersionUID = 1L;
+{{^useJackson3}}
private final static boolean DEFAULT_NORMALIZE_ZONE_ID = JavaTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault();
private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
= JavaTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault();
+{{/useJackson3}}
+{{#useJackson3}}
+ private final static boolean DEFAULT_NORMALIZE_ZONE_ID = DateTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault();
+ private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
+ = DateTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault();
+{{/useJackson3}}
public static final RFC3339InstantDeserializer INSTANT = new RFC3339InstantDeserializer<>(
Instant.class, DateTimeFormatter.ISO_INSTANT,
@@ -84,7 +102,7 @@ public class RFC3339InstantDeserializer extends InstantDeser
}
@Override
- protected T _fromString(JsonParser p, DeserializationContext ctxt, String string0) throws IOException {
+ protected T _fromString(JsonParser p, DeserializationContext ctxt, String string0) throws {{^useJackson3}}IOException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} {
return super._fromString(p, ctxt, string0.replace( ' ', 'T' ));
}
}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/Java/RFC3339JavaTimeModule.mustache b/modules/openapi-generator/src/main/resources/Java/RFC3339JavaTimeModule.mustache
index 6b780cd438ba..ade3882d95a8 100644
--- a/modules/openapi-generator/src/main/resources/Java/RFC3339JavaTimeModule.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/RFC3339JavaTimeModule.mustache
@@ -5,8 +5,10 @@ import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
-import com.fasterxml.jackson.databind.module.SimpleModule;
+import {{jacksonPackage}}.databind.module.SimpleModule;
+{{^useJackson3}}
import com.fasterxml.jackson.databind.Module.SetupContext;
+{{/useJackson3}}
{{>generatedAnnotation}}
@@ -15,8 +17,14 @@ public class RFC3339JavaTimeModule extends SimpleModule {
public RFC3339JavaTimeModule() {
super("RFC3339JavaTimeModule");
+ {{#useJackson3}}
+ addDeserializer(Instant.class, RFC3339InstantDeserializer.INSTANT);
+ addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME);
+ addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME);
+ {{/useJackson3}}
}
+ {{^useJackson3}}
@Override
public void setupModule(SetupContext context) {
super.setupModule(context);
@@ -25,5 +33,6 @@ public class RFC3339JavaTimeModule extends SimpleModule {
addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME);
addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME);
}
+ {{/useJackson3}}
}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache
index 0fd6071d3080..d6a3330066b8 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache
@@ -2,13 +2,20 @@
package {{invokerPackage}};
import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import {{jacksonPackage}}.databind.DeserializationFeature;
+import {{jacksonPackage}}.databind.ObjectMapper;
+{{^useJackson3}}
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{#openApiNullable}}
import org.openapitools.jackson.nullable.JsonNullableModule;
{{/openApiNullable}}
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.databind.cfg.DateTimeFeature;
+import tools.jackson.databind.cfg.EnumFeature;
+import tools.jackson.databind.json.JsonMapper;
+{{/useJackson3}}
import java.io.InputStream;
import java.io.IOException;
@@ -205,6 +212,7 @@ public class ApiClient {
}
public static ObjectMapper createDefaultObjectMapper() {
+{{^useJackson3}}
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -219,6 +227,19 @@ public class ApiClient {
{{/openApiNullable}}
mapper.registerModule(new RFC3339JavaTimeModule());
return mapper;
+{{/useJackson3}}
+{{#useJackson3}}
+ return JsonMapper.builder()
+ .changeDefaultPropertyInclusion(v -> v.withValueInclusion(JsonInclude.Include.NON_NULL))
+ .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
+ .disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)
+ .disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS)
+ .enable(EnumFeature.WRITE_ENUMS_USING_TO_STRING)
+ .enable(EnumFeature.READ_ENUMS_USING_TO_STRING)
+ .disable(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
+ .addModule(new RFC3339JavaTimeModule())
+ .build();
+{{/useJackson3}}
}
protected final String getDefaultBaseUri() {
@@ -273,12 +294,17 @@ public class ApiClient {
}
/**
- * Get a copy of the current {@link ObjectMapper}.
+ * Get {{^useJackson3}}a copy of {{/useJackson3}}the current {@link ObjectMapper}.
*
- * @return A copy of the current object mapper.
+ * @return {{^useJackson3}}A copy of the current{{/useJackson3}}{{#useJackson3}}The current{{/useJackson3}} object mapper.
*/
public ObjectMapper getObjectMapper() {
+{{^useJackson3}}
return mapper.copy();
+{{/useJackson3}}
+{{#useJackson3}}
+ return mapper;
+{{/useJackson3}}
}
/**
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/JSON.mustache
index a2020732513d..3d00cafc9033 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/JSON.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/JSON.mustache
@@ -3,14 +3,20 @@
package {{invokerPackage}};
import com.fasterxml.jackson.annotation.*;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.json.JsonMapper;
+import {{jacksonPackage}}.databind.*;
+import {{jacksonPackage}}.databind.json.JsonMapper;
+{{^useJackson3}}
{{#openApiNullable}}
import org.openapitools.jackson.nullable.JsonNullableModule;
{{/openApiNullable}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.databind.cfg.DateTimeFeature;
+import tools.jackson.databind.cfg.EnumFeature;
+{{/useJackson3}}
{{#joda}}
-import com.fasterxml.jackson.datatype.joda.JodaModule;
+import {{jacksonPackage}}.datatype.joda.JodaModule;
{{/joda}}
{{#models.0}}
import {{modelPackage}}.*;
@@ -28,6 +34,7 @@ public class JSON {
private ObjectMapper mapper;
public JSON() {
+ {{^useJackson3}}
mapper = JsonMapper.builder()
.serializationInclusion(JsonInclude.Include.NON_NULL)
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS)
@@ -51,6 +58,26 @@ public class JSON {
JsonNullableModule jnm = new JsonNullableModule();
mapper.registerModule(jnm);
{{/openApiNullable}}
+ {{/useJackson3}}
+ {{#useJackson3}}
+ JsonMapper.Builder jsonMapperBuilder = JsonMapper.builder()
+ .changeDefaultPropertyInclusion(v -> v.withValueInclusion(JsonInclude.Include.NON_NULL))
+ {{#failOnUnknownProperties}}
+ .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
+ {{/failOnUnknownProperties}}
+ {{^failOnUnknownProperties}}
+ .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
+ {{/failOnUnknownProperties}}
+ .enable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)
+ .disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS)
+ .enable(EnumFeature.WRITE_ENUMS_USING_TO_STRING)
+ .enable(EnumFeature.READ_ENUMS_USING_TO_STRING)
+ .defaultDateFormat(new RFC3339DateFormat());
+ {{#joda}}
+ jsonMapperBuilder.addModule(new JodaModule());
+ {{/joda}}
+ mapper = jsonMapperBuilder.build();
+ {{/useJackson3}}
}
/**
@@ -59,7 +86,12 @@ public class JSON {
* @param dateFormat Date format
*/
public void setDateFormat(DateFormat dateFormat) {
+{{^useJackson3}}
mapper.setDateFormat(dateFormat);
+{{/useJackson3}}
+{{#useJackson3}}
+ mapper = ((JsonMapper) mapper).rebuild().defaultDateFormat(dateFormat).build();
+{{/useJackson3}}
}
/**
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/README.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/README.mustache
index fd7d4905a16e..2c0ca32e9e12 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/README.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/README.mustache
@@ -22,7 +22,7 @@
Building the API client library requires:
-1. Java 11+
+{{^useJackson3}}1. Java 11+{{/useJackson3}}{{#useJackson3}}1. Java 17+{{/useJackson3}}
2. Maven/Gradle
## Installation
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache
index d23e9c86ad73..b34e4f63e7ac 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache
@@ -1,21 +1,30 @@
+{{^useJackson3}}
import java.io.IOException;
+{{/useJackson3}}
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
+{{^useJackson3}}
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.DatabindException;
+import tools.jackson.databind.SerializationContext;
+{{/useJackson3}}
+import {{jacksonPackage}}.core.JsonGenerator;
+import {{jacksonPackage}}.core.JsonParser;
+import {{jacksonPackage}}.databind.DeserializationContext;
+import {{jacksonPackage}}.databind.JsonNode;
+import {{jacksonPackage}}.databind.annotation.JsonDeserialize;
+import {{jacksonPackage}}.databind.annotation.JsonSerialize;
+import {{jacksonPackage}}.databind.deser.std.StdDeserializer;
+import {{jacksonPackage}}.databind.ser.std.StdSerializer;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.JSON;
@@ -35,8 +44,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
@Override
- public void serialize({{classname}} value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
+ public void serialize({{classname}} value, JsonGenerator jgen, {{^useJackson3}}SerializerProvider provider{{/useJackson3}}{{#useJackson3}}SerializationContext serializationContext{{/useJackson3}}) throws {{^useJackson3}}IOException, JsonProcessingException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} {
+{{^useJackson3}}
jgen.writeObject(value.getActualInstance());
+{{/useJackson3}}
+{{#useJackson3}}
+ serializationContext.writeValue(jgen, value.getActualInstance());
+{{/useJackson3}}
}
}
@@ -50,7 +64,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
@Override
- public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
+ public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws {{^useJackson3}}IOException, JsonProcessingException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} {
JsonNode tree = ctxt.readTree(jp);
Object deserialized = null;
@@ -60,7 +74,12 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
// When the OAS schema includes a discriminator, use the discriminator value to
// discriminate the anyOf schemas.
// Get the discriminator mapping value to get the class.
+{{^useJackson3}}
deserialized = tree.traverse(jp.getCodec()).readValueAs(cls);
+{{/useJackson3}}
+{{#useJackson3}}
+ deserialized = ctxt.readTreeAsValue(tree, ctxt.constructType(cls));
+{{/useJackson3}}
{{classname}} ret = new {{classname}}();
ret.setActualInstance(deserialized);
return ret;
@@ -69,7 +88,12 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{#anyOf}}
// deserialize {{{.}}}
try {
+{{^useJackson3}}
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
+{{/useJackson3}}
+{{#useJackson3}}
+ deserialized = ctxt.readTreeAsValue(tree, {{{.}}}.class);
+{{/useJackson3}}
{{classname}} ret = new {{classname}}();
ret.setActualInstance(deserialized);
return ret;
@@ -79,19 +103,34 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
{{/anyOf}}
+{{^useJackson3}}
throw new IOException("Failed deserialization for {{classname}}: no match found");
+{{/useJackson3}}
+{{#useJackson3}}
+ throw DatabindException.from(jp, "Failed deserialization for {{classname}}: no match found");
+{{/useJackson3}}
}
/**
* Handle deserialization of the 'null' value.
*/
@Override
+{{^useJackson3}}
public {{classname}} getNullValue(DeserializationContext ctxt) throws JsonMappingException {
+{{/useJackson3}}
+{{#useJackson3}}
+ public {{classname}} getNullValue(DeserializationContext ctxt) {
+{{/useJackson3}}
{{#isNullable}}
return null;
{{/isNullable}}
{{^isNullable}}
+{{^useJackson3}}
throw new JsonMappingException(ctxt.getParser(), "{{classname}} cannot be null");
+{{/useJackson3}}
+{{#useJackson3}}
+ throw DatabindException.from(ctxt.getParser(), "{{classname}} cannot be null");
+{{/useJackson3}}
{{/isNullable}}
}
}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
index b65b8f3950ef..901c6bcb45b7 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
@@ -11,8 +11,11 @@ import {{invokerPackage}}.Pair;
import {{import}};
{{/imports}}
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+{{#useJackson3}}
+import tools.jackson.core.JacksonException;
+{{/useJackson3}}
+import {{jacksonPackage}}.core.type.TypeReference;
+import {{jacksonPackage}}.databind.ObjectMapper;
{{#useBeanValidation}}
import {{javaxPackage}}.validation.constraints.*;
@@ -524,7 +527,7 @@ public class {{classname}} {
localVarResponseBody.close();
}
}
- } catch (IOException e) {
+ } catch (IOException {{#returnType}}{{#useJackson3}}| JacksonException {{/useJackson3}}{{/returnType}}e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
@@ -611,7 +614,7 @@ public class {{classname}} {
localVarResponseBody.close();
}
}
- } catch (IOException e) {
+ } catch (IOException {{#returnType}}{{#useJackson3}}| JacksonException {{/useJackson3}}{{/returnType}}e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
}
@@ -742,7 +745,7 @@ public class {{classname}} {
{{^useGzipFeature}}
localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
{{/useGzipFeature}}
- } catch (IOException e) {
+ } catch ({{^useJackson3}}IOException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} e) {
throw new ApiException(e);
}
{{/isString}}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/api_doc.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/api_doc.mustache
index 2b125e1f9cad..eb6ca1dd1e4c 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/api_doc.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/api_doc.mustache
@@ -136,10 +136,10 @@ public class Example {
## {{operationId}}WithHttpInfo
{{^vendorExtensions.x-group-parameters}}
-> {{#asyncNative}}CompletableFuture<{{/asyncNative}}ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>{{#asyncNative}}>{{/asyncNative}} {{operationId}} {{operationId}}WithHttpInfo({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
+> {{#asyncNative}}CompletableFuture<{{/asyncNative}}ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>{{#asyncNative}}>{{/asyncNative}} {{operationId}}WithHttpInfo({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
-> {{#asyncNative}}CompletableFuture<{{/asyncNative}}ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>{{#asyncNative}}>{{/asyncNative}} {{operationId}} {{operationId}}WithHttpInfo({{#hasParams}}{{operationId}}Request{{/hasParams}})
+> {{#asyncNative}}CompletableFuture<{{/asyncNative}}ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>{{#asyncNative}}>{{/asyncNative}} {{operationId}}WithHttpInfo({{#hasParams}}{{operationId}}Request{{/hasParams}})
{{/vendorExtensions.x-group-parameters}}
{{summary}}{{#notes}}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache
index 8e92f860d7ad..12e9b866edf0 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache
@@ -21,8 +21,14 @@ repositories {
apply plugin: 'java'
apply plugin: 'maven-publish'
+{{^useJackson3}}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
+{{/useJackson3}}
+{{#useJackson3}}
+sourceCompatibility = JavaVersion.VERSION_17
+targetCompatibility = JavaVersion.VERSION_17
+{{/useJackson3}}
// Some text from the schema is copy pasted into the source files as UTF-8
// but the default still seems to be to use platform encoding
@@ -72,8 +78,14 @@ ext {
{{#swagger2AnnotationLibrary}}
swagger_annotations_version = "2.2.9"
{{/swagger2AnnotationLibrary}}
+ {{^useJackson3}}
jackson_version = "2.21.1"
jackson_annotations_version = "2.21"
+ {{/useJackson3}}
+ {{#useJackson3}}
+ jackson3_version = "3.1.0"
+ jackson_annotations_version = "2.21"
+ {{/useJackson3}}
{{#useJakartaEe}}
jakarta_annotation_version = "2.1.1"
beanvalidation_version = "3.0.2"
@@ -99,11 +111,18 @@ dependencies {
implementation "io.swagger.core.v3:swagger-annotations:$swagger_annotations_version"
{{/swagger2AnnotationLibrary}}
implementation "com.google.code.findbugs:jsr305:3.0.2"
+ {{^useJackson3}}
implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_annotations_version"
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
implementation "org.openapitools:jackson-databind-nullable:0.2.9"
+ {{/useJackson3}}
+ {{#useJackson3}}
+ implementation "tools.jackson.core:jackson-core:$jackson3_version"
+ implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_annotations_version"
+ implementation "tools.jackson.core:jackson-databind:$jackson3_version"
+ {{/useJackson3}}
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
{{#useBeanValidation}}
implementation "jakarta.validation:jakarta.validation-api:$beanvalidation_version"
@@ -115,6 +134,11 @@ dependencies {
implementation "org.apache.commons:commons-lang3:$commons_lang3_version"
{{/useReflectionEqualsHashCode}}
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
+ testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
+}
+
+test {
+ useJUnitPlatform()
}
// Use spotless plugin to automatically format code, remove unused import, etc
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache
index b3beca8d3273..de11a5bd86dd 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache
@@ -58,7 +58,7 @@ import org.hibernate.validator.constraints.*;
{{#model}}
{{#oneOf}}
{{#-first}}
-import com.fasterxml.jackson.core.type.TypeReference;
+import {{jacksonPackage}}.core.type.TypeReference;
{{/-first}}
{{/oneOf}}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache
index e4b71623b29c..2b28229f94d9 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache
@@ -1,23 +1,32 @@
+{{^useJackson3}}
import java.io.IOException;
+{{/useJackson3}}
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
+{{^useJackson3}}
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.JsonToken;
-import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.DatabindException;
+import tools.jackson.databind.SerializationContext;
+{{/useJackson3}}
+import {{jacksonPackage}}.core.JsonGenerator;
+import {{jacksonPackage}}.core.JsonParser;
+import {{jacksonPackage}}.core.JsonToken;
+import {{jacksonPackage}}.databind.DeserializationContext;
+import {{jacksonPackage}}.databind.JsonNode;
+import {{jacksonPackage}}.databind.annotation.JsonDeserialize;
+import {{jacksonPackage}}.databind.annotation.JsonSerialize;
+import {{jacksonPackage}}.databind.deser.std.StdDeserializer;
+import {{jacksonPackage}}.databind.ser.std.StdSerializer;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.JSON;
@@ -37,8 +46,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
@Override
- public void serialize({{classname}} value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
+ public void serialize({{classname}} value, JsonGenerator jgen, {{^useJackson3}}SerializerProvider provider{{/useJackson3}}{{#useJackson3}}SerializationContext serializationContext{{/useJackson3}}) throws {{^useJackson3}}IOException, JsonProcessingException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} {
+{{^useJackson3}}
jgen.writeObject(value.getActualInstance());
+{{/useJackson3}}
+{{#useJackson3}}
+ serializationContext.writeValue(jgen, value.getActualInstance());
+{{/useJackson3}}
}
}
@@ -52,18 +66,28 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
@Override
- public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
+ public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws {{^useJackson3}}IOException, JsonProcessingException{{/useJackson3}}{{#useJackson3}}JacksonException{{/useJackson3}} {
JsonNode tree = ctxt.readTree(jp);
Object deserialized = null;
{{#useOneOfDiscriminatorLookup}}
{{#discriminator}}
{{classname}} new{{classname}} = new {{classname}}();
+{{^useJackson3}}
Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference