Skip to content

fix(kotlin-spring): use Jackson 3 annotation package in model imports#23406

Open
yonatankarp wants to merge 1 commit intoOpenAPITools:masterfrom
yonatankarp:fix/kotlin-spring-jackson3-imports
Open

fix(kotlin-spring): use Jackson 3 annotation package in model imports#23406
yonatankarp wants to merge 1 commit intoOpenAPITools:masterfrom
yonatankarp:fix/kotlin-spring-jackson3-imports

Conversation

@yonatankarp
Copy link
Copy Markdown
Contributor

@yonatankarp yonatankarp commented Apr 1, 2026

Summary

  • Fixes importMapping in KotlinSpringServerCodegen to derive Jackson annotation package from useJackson3 flag instead of hardcoding com.fasterxml.jackson
  • Adds missing tools.jackson.core:jackson-annotations dependency to all Spring Boot 4 build templates (Gradle + Maven) for spring-boot, spring-cloud, and spring-declarative-http-interface libraries
  • Fixes hardcoded com.fasterxml.jackson.dataformat.yaml.YAMLMapper import in homeController.mustache to use {{jacksonPackage}}
  • Adds test verifying generated model files use tools.jackson.annotation when Jackson 3 is enabled
  • Regenerates kotlin-springboot-4 sample with corrected imports and dependencies

Bug

When using useSpringBoot4: true / useJackson3: true with the kotlin-spring generator:

  1. Generated model source files imported com.fasterxml.jackson.annotation.* (Jackson 2) instead of tools.jackson.annotation.* (Jackson 3)
  2. Build files were missing the tools.jackson.core:jackson-annotations dependency, causing compile failures even after fixing the imports

Summary by cubic

Fix Kotlin Spring generation for Jackson 3 on Spring Boot 4: keep model annotations in com.fasterxml.jackson.annotation, use {{jacksonPackage}} for YAMLMapper, and pin Jackson 3 dataformat/module versions. Tests and Spring Boot 4 samples updated.

  • Bug Fixes

    • KotlinSpringServerCodegen: always import JsonProperty/JsonCreator/JsonValue from com.fasterxml.jackson.annotation (annotations did not move in Jackson 3).
    • homeController.mustache: import {{jacksonPackage}}.dataformat.yaml.YAMLMapper.
  • Dependencies

    • Spring Boot 4 templates: set 3.1.0 for tools.jackson.dataformat:jackson-dataformat-yaml, tools.jackson.dataformat:jackson-dataformat-xml, and tools.jackson.module:jackson-module-kotlin via val jackson3Version / <jackson3.version>.
    • Do not add tools.jackson.core:jackson-annotations.

Written for commit 9e9bff4. Summary will update on new commits.

@yonatankarp yonatankarp force-pushed the fix/kotlin-spring-jackson3-imports branch 4 times, most recently from 023d654 to dc3ff1e Compare April 1, 2026 12:09
@yonatankarp yonatankarp marked this pull request as ready for review April 1, 2026 12:50
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 11 files

…ring Boot 4

Spring Boot 4's BOM does not manage tools.jackson.* artifacts, so Jackson 3
dataformat and module dependencies need explicit versions. Also fixes the
hardcoded YAMLMapper import in homeController.mustache to use the
jacksonPackage template variable.

Note: Jackson annotations stay in com.fasterxml.jackson.annotation even
for Jackson 3 — only core, databind, dataformat and module jars moved to
the tools.jackson group.
@yonatankarp yonatankarp force-pushed the fix/kotlin-spring-jackson3-imports branch from dc3ff1e to 9e9bff4 Compare April 1, 2026 13:00
@Picazsoo
Copy link
Copy Markdown
Contributor

Picazsoo commented Apr 1, 2026

If you added a test, it would be good to revert the implementation (leave the test intact), push, let the test fail and the again restore the fix and push and let the test pass. That way it is somewhat proven that the test passes because it tests for the issue.
You can think of it like a fake TDD.

@yonatankarp
Copy link
Copy Markdown
Contributor Author

yonatankarp commented Apr 1, 2026

@Picazsoo it was done like that, I squashed them before I asked for a review, but next time I'm happy to keep the commits separated 😄

@Picazsoo
Copy link
Copy Markdown
Contributor

Picazsoo commented Apr 1, 2026

Sorry, that did not occur to me

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.

2 participants