diff --git a/bin/configs/jaxrs-cxf-client-jackson.yaml b/bin/configs/jaxrs-cxf-client-jackson.yaml index 86cb90696fe7..70b64667d5ba 100644 --- a/bin/configs/jaxrs-cxf-client-jackson.yaml +++ b/bin/configs/jaxrs-cxf-client-jackson.yaml @@ -5,3 +5,5 @@ templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/cxf additionalProperties: artifactId: jaxrs-cxf-jackson-petstore-client jackson: "true" + useJackson3: "true" + useJakartaEe: "true" \ No newline at end of file diff --git a/docs/generators/jaxrs-cxf-client.md b/docs/generators/jaxrs-cxf-client.md index 58557b0ba047..a3835496fda8 100644 --- a/docs/generators/jaxrs-cxf-client.md +++ b/docs/generators/jaxrs-cxf-client.md @@ -76,6 +76,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useBeanValidation|Use BeanValidation API annotations| |false| |useGenericResponse|Use generic response| |false| |useGzipFeatureForTests|Use Gzip Feature for tests| |false| +|useJackson3|Use Jackson 3 instead of Jackson 2.| |false| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useLoggingFeatureForTests|Use Logging Feature for tests| |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/JavaCXFClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFClientCodegen.java index eed6ae36da88..1da91379f095 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFClientCodegen.java @@ -51,6 +51,11 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles"; + public static final String USE_JACKSON_3 = "useJackson3"; + public static final String JACKSON2_PACKAGE = "com.fasterxml.jackson"; + public static final String JACKSON3_PACKAGE = "tools.jackson"; + public static final String JACKSON_PACKAGE = "jacksonPackage"; + @Getter protected boolean useGenericResponse = false; @Getter protected boolean useGzipFeatureForTests = false; @@ -59,6 +64,8 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen @Setter protected boolean useAbstractionForFiles = false; + @Getter @Setter protected boolean useJackson3 = false; + public JavaCXFClientCodegen() { super(); @@ -97,6 +104,8 @@ public JavaCXFClientCodegen() { cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE_FOR_TESTS, "Use Logging Feature for tests")); cliOptions.add(CliOption.newBoolean(USE_GENERIC_RESPONSE, "Use generic response")); cliOptions.add(CliOption.newBoolean(USE_ABSTRACTION_FOR_FILES, "Use alternative types instead of java.io.File to allow passing bytes without a file on disk.")); + cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 instead of Jackson 2.", this.useJackson3)); + } @Override @@ -107,7 +116,13 @@ public void processOpts() { convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS, this::setUseLoggingFeatureForTests); convertPropertyToBooleanAndWriteBack(JACKSON, this::setJackson); convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES, this::setUseAbstractionForFiles); + convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3); + if (this.useJackson3) { + this.applyJackson3Package(); + } else { + this.applyJackson2Package(); + } supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml") @@ -206,4 +221,12 @@ public void setUseGenericResponse(boolean useGenericResponse) { this.useGenericResponse = useGenericResponse; } + + protected void applyJackson2Package() { + writePropertyBack(JACKSON_PACKAGE, JACKSON2_PACKAGE); + } + + protected void applyJackson3Package() { + writePropertyBack(JACKSON_PACKAGE, JACKSON3_PACKAGE); + } } diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/api_test.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/api_test.mustache index 6e760e411a8c..52f1908f81ed 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/api_test.mustache @@ -24,7 +24,17 @@ import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; {{/useLoggingFeature}} +{{#useJackson3}} +import {{jacksonPackage}}.jakarta.rs.json.JacksonJsonProvider; +{{/useJackson3}} +{{^useJackson3}} +{{#useJakartaEe}} +import {{jacksonPackage}}.jakarta.rs.json.JacksonJsonProvider; +{{/useJakartaEe}} +{{^useJakartaEe}} import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +{{/useJakartaEe}} +{{/useJackson3}} import java.util.ArrayList; import java.util.HashMap; diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pom.mustache index 1adc6861f0d3..a679fc199338 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -102,7 +102,7 @@ - com.fasterxml.jackson + {{jacksonPackage}} jackson-bom ${jackson-jaxrs-version} pom @@ -196,7 +196,7 @@ for this project used jakarta.validation-api --> {{^useJakartaEe}} - com.fasterxml.jackson.jaxrs + {{jacksonPackage}}.jaxrs jackson-jaxrs-json-provider ${jackson-jaxrs-version} compile @@ -204,17 +204,19 @@ for this project used jakarta.validation-api --> {{/useJakartaEe}} {{#useJakartaEe}} - com.fasterxml.jackson.jakarta.rs + {{jacksonPackage}}.jakarta.rs jackson-jakarta-rs-json-provider ${jackson-jaxrs-version} compile {{/useJakartaEe}} + {{^useJackson3}} com.fasterxml.jackson.datatype jackson-datatype-jsr310 ${jackson-jaxrs-version} + {{/useJackson3}} {{#useBeanValidationFeature}} org.hibernate @@ -244,9 +246,6 @@ for this project used jakarta.validation-api --> - 1.8 - ${java.version} - ${java.version} {{#swagger1AnnotationLibrary}} 1.6.6 {{/swagger1AnnotationLibrary}} @@ -259,8 +258,14 @@ for this project used jakarta.validation-api --> {{#useBeanValidation}} 2.0.2 {{/useBeanValidation}} + {{#useJackson3}} + 4.2.0 + 3.1.2 + {{/useJackson3}} + {{^useJackson3}} 3.5.9 2.17.1 + {{/useJackson3}} {{#useJakartaEe}} 2.1.1 {{/useJakartaEe}} diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/pom.xml b/samples/client/petstore/jaxrs-cxf-client-jackson/pom.xml index 225668bf584e..c928be8f44c4 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/pom.xml +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/pom.xml @@ -84,7 +84,7 @@ - com.fasterxml.jackson + tools.jackson jackson-bom ${jackson-jaxrs-version} pom @@ -159,16 +159,11 @@ for this project used jakarta.validation-api --> compile - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider + tools.jackson.jakarta.rs + jackson-jakarta-rs-json-provider ${jackson-jaxrs-version} compile - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${jackson-jaxrs-version} - jakarta.annotation jakarta.annotation-api @@ -191,16 +186,13 @@ for this project used jakarta.validation-api --> - 1.8 - ${java.version} - ${java.version} 1.6.6 9.2.9.v20150224 4.13.2 1.5.25 - 3.5.9 - 2.17.1 - 1.3.5 + 4.2.0 + 3.1.2 + 2.1.1 UTF-8 diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/PetApi.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/PetApi.java index 9ed0722a827a..59b14eed1050 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/PetApi.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/PetApi.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.*; +import jakarta.ws.rs.*; import org.apache.cxf.jaxrs.ext.multipart.*; import io.swagger.annotations.Api; diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/StoreApi.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/StoreApi.java index 89f06783cef6..963bd880873a 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/StoreApi.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/StoreApi.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.*; +import jakarta.ws.rs.*; import org.apache.cxf.jaxrs.ext.multipart.*; import io.swagger.annotations.Api; diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/UserApi.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/UserApi.java index 3b1dd0ef5745..d1c687771abe 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/UserApi.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/gen/java/org/openapitools/api/UserApi.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.*; +import jakarta.ws.rs.*; import org.apache.cxf.jaxrs.ext.multipart.*; import io.swagger.annotations.Api; diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/PetApiTest.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/PetApiTest.java index 5fc4823c1c74..32f583cf704a 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/PetApiTest.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/PetApiTest.java @@ -1,4 +1,4 @@ -/** +/* * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * @@ -20,13 +20,13 @@ import org.junit.Before; import static org.junit.Assert.*; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.ClientConfiguration; import org.apache.cxf.jaxrs.client.WebClient; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import tools.jackson.jakarta.rs.json.JacksonJsonProvider; import java.util.ArrayList; import java.util.HashMap; diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/StoreApiTest.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/StoreApiTest.java index b5c96c77b9bd..9a8c4637e59f 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/StoreApiTest.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/StoreApiTest.java @@ -1,4 +1,4 @@ -/** +/* * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * @@ -18,13 +18,13 @@ import org.junit.Before; import static org.junit.Assert.*; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.ClientConfiguration; import org.apache.cxf.jaxrs.client.WebClient; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import tools.jackson.jakarta.rs.json.JacksonJsonProvider; import java.util.ArrayList; import java.util.HashMap; diff --git a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/UserApiTest.java b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/UserApiTest.java index 0825dbb0f6e7..231ea93dfe3a 100644 --- a/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/UserApiTest.java +++ b/samples/client/petstore/jaxrs-cxf-client-jackson/src/test/java/org/openapitools/api/UserApiTest.java @@ -1,4 +1,4 @@ -/** +/* * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * @@ -19,13 +19,13 @@ import org.junit.Before; import static org.junit.Assert.*; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.ClientConfiguration; import org.apache.cxf.jaxrs.client.WebClient; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import tools.jackson.jakarta.rs.json.JacksonJsonProvider; import java.util.ArrayList; import java.util.HashMap; diff --git a/samples/client/petstore/jaxrs-cxf-client-swagger2/pom.xml b/samples/client/petstore/jaxrs-cxf-client-swagger2/pom.xml index eb1bd70a9a9a..d63383c8cdcc 100644 --- a/samples/client/petstore/jaxrs-cxf-client-swagger2/pom.xml +++ b/samples/client/petstore/jaxrs-cxf-client-swagger2/pom.xml @@ -182,9 +182,6 @@ - 1.8 - ${java.version} - ${java.version} 2.2.7 9.2.9.v20150224 4.13.2 diff --git a/samples/client/petstore/jaxrs-cxf-client/pom.xml b/samples/client/petstore/jaxrs-cxf-client/pom.xml index df3f3f94d350..1c40abf47c55 100644 --- a/samples/client/petstore/jaxrs-cxf-client/pom.xml +++ b/samples/client/petstore/jaxrs-cxf-client/pom.xml @@ -191,9 +191,6 @@ for this project used jakarta.validation-api --> - 1.8 - ${java.version} - ${java.version} 1.6.6 9.2.9.v20150224 4.13.2