Skip to content

feat(kotlin-client): add Jackson 3 support with useJackson3 option#23161

Draft
yonatankarp wants to merge 3 commits intoOpenAPITools:masterfrom
yonatankarp:feat/kotlin-client-jackson3
Draft

feat(kotlin-client): add Jackson 3 support with useJackson3 option#23161
yonatankarp wants to merge 3 commits intoOpenAPITools:masterfrom
yonatankarp:feat/kotlin-client-jackson3

Conversation

@yonatankarp
Copy link
Contributor

@yonatankarp yonatankarp commented Mar 6, 2026

Summary

  • Wire the existing AbstractKotlinCodegen Jackson 3 infrastructure into the kotlin client generator
  • When useJackson3=true (requires serializationLibrary=jackson), all templates use the tools.jackson package instead of com.fasterxml.jackson, and build.gradle pulls jackson-module-kotlin 3.0.1 without the separate JSR-310 module
  • Register useJackson3 CLI option with validation (requires jackson serialization, incompatible with openApiNullable)
  • Replace hardcoded com.fasterxml.jackson with {{jacksonPackage}} in all model, serializer, and library-specific templates
  • Make JavaTimeModule conditional (not needed in Jackson 3) for jvm-ktor
  • Add tests for validation and generated output
  • Add kotlin-jackson3 sample config, generated sample, CI workflow entry, and regenerated docs

Test plan

  • Unit tests pass: validation rejects useJackson3 with non-jackson serialization and with openApiNullable
  • Generated model files contain import tools.jackson.annotation.JsonProperty (not com.fasterxml.jackson)
  • Generated build.gradle contains tools.jackson.module:jackson-module-kotlin and no jackson-datatype-jsr310
  • Existing Jackson 2 samples regenerate identically (no diffs)
  • CI passes on samples-kotlin-client workflow

Summary by cubic

Adds Jackson 3 support to the Kotlin client via a new useJackson3 option. Switches templates to tools.jackson for databind/core/module, keeps annotations at com.fasterxml.jackson.annotation, updates Gradle deps, and adjusts the serializer for Jackson 3 API changes.

  • New Features

    • Added useJackson3 CLI option with validation (requires serializationLibrary=jackson; incompatible with openApiNullable).
    • Templates use {{jacksonPackage}} across models and JVM clients; annotations stay com.fasterxml.jackson.annotation; jvm-ktor registers JavaTimeModule only for Jackson 2.
    • Serializer template updated for Jackson 3: uses DateTimeFeature and EnumFeature, and removes findAndRegisterModules; SerializationFeature import gated to Jackson 2.
    • Gradle pulls tools.jackson.module:jackson-module-kotlin:3.0.1 when enabled and omits jackson-datatype-jsr310.
    • Added kotlin-jackson3 sample and CI entry; updated generator docs.
    • Tests cover option validation and generated imports/dependencies; Jackson 2 samples regenerate unchanged.
  • Migration

    • Enable with: -p serializationLibrary=jackson -p useJackson3=true.
    • Do not combine with openApiNullable.
    • Generated code uses tools.jackson.* for databind/core/module and com.fasterxml.jackson.annotation for annotations; jvm-ktor does not register JavaTimeModule under Jackson 3.

Written for commit e657ce3. Summary will update on new commits.

Wire the existing AbstractKotlinCodegen Jackson 3 infrastructure into
the kotlin client generator. When useJackson3=true (requires
serializationLibrary=jackson), all templates use the tools.jackson
package instead of com.fasterxml.jackson, and build.gradle pulls
jackson-module-kotlin 3.0.1 without the separate JSR-310 module.

- Register useJackson3 CLI option in KotlinClientCodegen
- Add validation: requires jackson serialization, incompatible with openApiNullable
- Replace hardcoded com.fasterxml.jackson with {{jacksonPackage}} in all
  model, serializer, and library-specific templates
- Make JavaTimeModule conditional (not needed in Jackson 3) for jvm-ktor
- Add Jackson 3 dependency block in build.gradle.mustache
- Add tests for validation and generated output
- Add kotlin-jackson3 sample config and generated sample
- Add sample to CI workflow matrix
- Regenerate generator docs
@yonatankarp yonatankarp force-pushed the feat/kotlin-client-jackson3 branch from 2bdb660 to 4535b51 Compare March 6, 2026 17:03
Jackson 3 only moves databind/core/module to tools.jackson package.
The annotations artifact stays at com.fasterxml.jackson.annotation.
Also add AbstractKotlinCodegen Jackson 3 infrastructure so this branch
is self-contained for CI testing.
Jackson 3 moved/renamed several APIs:
- findAndRegisterModules() not needed (modules auto-discovered)
- SerializationFeature.WRITE_DATES_AS_TIMESTAMPS -> DateTimeFeature
- DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE -> EnumFeature

Add conditionals in Serializer.kt.mustache for Jackson 2 vs 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant