-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
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 |
|---|---|---|
|
|
@@ -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}} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md |

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