-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat(kotlin-client): add Jackson 3 support with useJackson3 option #23161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
60adf19
7829af0
1117720
79dde3e
7849999
69d1430
d0fb3d4
00b3413
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-jackson3 | ||
| inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| serializationLibrary: jackson | ||
| useJackson3: "true" | ||
| artifactId: kotlin-petstore-jackson3 | ||
| enumPropertyNaming: UPPERCASE | ||
| enumUnknownDefaultCase: "true" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-jvm-spring-4-restclient-jackson3 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add this new folder to the workflow file as well (samples-kotlin-client.yaml)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yap, I moved it from draft just to trigger the review - thanks for the comment! |
||
| library: jvm-spring-restclient | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-petstore-spring4-restclient-jackson3 | ||
| enumUnknownDefaultCase: "true" | ||
| serializationLibrary: jackson | ||
| useSpringBoot4: "true" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -88,6 +88,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { | |||||||||||||||||||
| public static final String USE_SETTINGS_GRADLE = "useSettingsGradle"; | ||||||||||||||||||||
| public static final String IDEA = "idea"; | ||||||||||||||||||||
| public static final String USE_SPRING_BOOT3 = "useSpringBoot3"; | ||||||||||||||||||||
| public static final String USE_SPRING_BOOT4 = "useSpringBoot4"; | ||||||||||||||||||||
| public static final String USE_RESPONSE_AS_RETURN_TYPE = "useResponseAsReturnType"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public static final String DATE_LIBRARY = "dateLibrary"; | ||||||||||||||||||||
|
|
@@ -271,6 +272,7 @@ public KotlinClientCodegen() { | |||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_RX_JAVA3, "Whether to use the RxJava3 adapter with the retrofit2 library.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines adapter with the retrofit2 library.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT3, "Whether to use the Spring Boot 3 with the jvm-spring-webclient library.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Use Spring Boot 4 with the jvm-spring-restclient or jvm-spring-webclient library. Implies useJackson3.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(OMIT_GRADLE_PLUGIN_VERSIONS, "Whether to declare Gradle plugin versions in build files.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(OMIT_GRADLE_WRAPPER, "Whether to omit Gradle wrapper for creating a sub project.")); | ||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_SETTINGS_GRADLE, "Whether the project uses settings.gradle.")); | ||||||||||||||||||||
|
|
@@ -300,7 +302,7 @@ public KotlinClientCodegen() { | |||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_RESPONSE_AS_RETURN_TYPE, "When using retrofit2 and coroutines, use `Response`<`T`> as return type instead of `T`.", true)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, | ||||||||||||||||||||
| "Use Jackson 3 dependencies (tools.jackson package). Not yet supported for kotlin-client; reserved for future use.")); | ||||||||||||||||||||
| "Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable.")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
|
|
@@ -469,9 +471,10 @@ public void processOpts() { | |||||||||||||||||||
| convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (isUseJackson3()) { | ||||||||||||||||||||
| throw new IllegalArgumentException( | ||||||||||||||||||||
| "useJackson3 is not yet supported for kotlin-client. Jackson 3 support for kotlin-client will be added in a future release."); | ||||||||||||||||||||
| if (additionalProperties.containsKey(USE_SPRING_BOOT4)) { | ||||||||||||||||||||
| convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4); | ||||||||||||||||||||
| additionalProperties.put(USE_JACKSON_3, "true"); | ||||||||||||||||||||
| setUseJackson3(true); | ||||||||||||||||||||
|
Comment on lines
+474
to
+477
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: BUG: Setting Prompt for AI agents
Suggested change
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) { | ||||||||||||||||||||
|
|
@@ -481,6 +484,16 @@ public void processOpts() { | |||||||||||||||||||
| additionalProperties.put(this.serializationLibrary.name(), true); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (isUseJackson3()) { | ||||||||||||||||||||
| if (this.serializationLibrary != SERIALIZATION_LIBRARY_TYPE.jackson) { | ||||||||||||||||||||
| throw new IllegalArgumentException("useJackson3 requires serializationLibrary=jackson"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (additionalProperties.containsKey("openApiNullable") | ||||||||||||||||||||
| && Boolean.parseBoolean(additionalProperties.get("openApiNullable").toString())) { | ||||||||||||||||||||
| throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (additionalProperties.containsKey(MAP_FILE_BINARY_TO_BYTE_ARRAY)) { | ||||||||||||||||||||
| setMapFileBinaryToByteArray(convertPropertyToBooleanAndWriteBack(MAP_FILE_BINARY_TO_BYTE_ARRAY)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -864,8 +877,9 @@ private void processJvmSpringWebClientLibrary(final String infrastructureFolder) | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private void processJvmSpringRestClientLibrary(final String infrastructureFolder) { | ||||||||||||||||||||
| if (additionalProperties.getOrDefault(USE_SPRING_BOOT3, false).equals(false)) { | ||||||||||||||||||||
| throw new RuntimeException("This library must use Spring Boot 3. Try adding '--additional-properties useSpringBoot3=true' to your command."); | ||||||||||||||||||||
| if (additionalProperties.getOrDefault(USE_SPRING_BOOT3, false).equals(false) | ||||||||||||||||||||
| && additionalProperties.getOrDefault(USE_SPRING_BOOT4, false).equals(false)) { | ||||||||||||||||||||
| throw new RuntimeException("This library requires Spring Boot 3 or 4. Try adding '--additional-properties useSpringBoot3=true' or '--additional-properties useSpringBoot4=true' to your command."); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| processJvmSpring(infrastructureFolder); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,11 +30,24 @@ import kotlinx.datetime.LocalTime | |
| import java.util.UUID | ||
| {{/gson}} | ||
| {{#jackson}} | ||
| import com.fasterxml.jackson.databind.DeserializationFeature | ||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
| import com.fasterxml.jackson.databind.SerializationFeature | ||
| {{^useJackson3}} | ||
| import {{jacksonPackage}}.databind.DeserializationFeature | ||
| import {{jacksonPackage}}.databind.ObjectMapper | ||
| import {{jacksonPackage}}.databind.SerializationFeature | ||
| import com.fasterxml.jackson.annotation.JsonInclude | ||
| import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
| import {{jacksonPackage}}.module.kotlin.jacksonObjectMapper | ||
| {{/useJackson3}} | ||
| {{#useJackson3}} | ||
| import {{jacksonPackage}}.databind.DeserializationFeature | ||
| import {{jacksonPackage}}.databind.ObjectMapper | ||
| import {{jacksonPackage}}.databind.cfg.DateTimeFeature | ||
| {{#enumUnknownDefaultCase}} | ||
| import {{jacksonPackage}}.databind.cfg.EnumFeature | ||
| {{/enumUnknownDefaultCase}} | ||
| import com.fasterxml.jackson.annotation.JsonInclude | ||
| import {{jacksonPackage}}.module.kotlin.jsonMapper | ||
| import {{jacksonPackage}}.module.kotlin.kotlinModule | ||
| {{/useJackson3}} | ||
| {{/jackson}} | ||
| {{#kotlinx_serialization}} | ||
| import java.math.BigDecimal | ||
|
|
@@ -120,6 +133,7 @@ import java.util.concurrent.atomic.AtomicLong | |
| } | ||
| {{/gson}} | ||
| {{#jackson}} | ||
| {{^useJackson3}} | ||
| @JvmStatic | ||
| val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper() | ||
| .findAndRegisterModules() | ||
|
|
@@ -129,6 +143,24 @@ import java.util.concurrent.atomic.AtomicLong | |
| {{/enumUnknownDefaultCase}} | ||
| .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) | ||
| .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, {{failOnUnknownProperties}}) | ||
| {{/useJackson3}} | ||
| {{#useJackson3}} | ||
| @JvmStatic | ||
| val jacksonObjectMapper: ObjectMapper = jsonMapper { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the type of Especially if it is to be used with in the generated code for the client, which passes it to a |
||
| addModule(kotlinModule()) | ||
| changeDefaultPropertyInclusion { it.withValueInclusion(JsonInclude.Include.NON_ABSENT) } | ||
| {{#enumUnknownDefaultCase}} | ||
| enable(EnumFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) | ||
| {{/enumUnknownDefaultCase}} | ||
| disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the default for this serialization feature I believe the same applies for |
||
| {{#failOnUnknownProperties}} | ||
| enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
| {{/failOnUnknownProperties}} | ||
| {{^failOnUnknownProperties}} | ||
| disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
| {{/failOnUnknownProperties}} | ||
| } | ||
| {{/useJackson3}} | ||
| {{/jackson}} | ||
| {{#kotlinx_serialization}} | ||
| private var isAdaptersInitialized = false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ import com.squareup.moshi.Moshi | |
| import retrofit2.converter.moshi.MoshiConverterFactory | ||
| {{/moshi}} | ||
| {{#jackson}} | ||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
| import {{jacksonPackage}}.databind.ObjectMapper | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Incompatible Jackson version with Retrofit2: Prompt for AI agents |
||
| import retrofit2.converter.jackson.JacksonConverterFactory | ||
| {{/jackson}} | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Missing CI coverage for new sample
kotlin-jvm-spring-4-restclient-jackson3. The PR addskotlin-jackson3to the workflow but omits the Spring Boot 4 Jackson 3 sample, creating a CI blind spot where this sample can break without detection.Prompt for AI agents