OpenAPITools / OpenAPITools/openapi-generator

[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=true

Open Beginner friendly
#24,842 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

7.25.0 breaks backward compatibility, by force-setting useJackson3=true for Spring 4 and jvm-spring-restclient

It's incorrect to enforce Jackson 3 with those settings: Spring 4.0 and 4.1 work with Jackson 2, it's just deprecated. RestClient still works with Jackson 2.

openapi-generator version

7.25.0, it's a regression compared to 7.24.0

OpenAPI declaration file content or url
Generation Details

See 'steps to reproduce'

Steps to reproduce

I only generate sources and use my own build.gradle.kts, throwing away generator's one.

dependencies {
    api(platform("org.springframework.boot:spring-boot-dependencies:4.0.8"))

    api("org.springframework:spring-web")

    // api because Serializer.jacksonObjectMapper is public
    api("com.fasterxml.jackson.core:jackson-databind")
    api("org.openapitools:jackson-databind-nullable:0.2.11")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
}

openApiGenerate {
    configOptions.set(
        mapOf(
            "omitGradleWrapper" to "true",
            "library" to "jvm-spring-restclient",
            "useSpringBoot3" to "true",
            "useSpringBoot4" to "true",
            "useJackson3" to "false",
            "serializationLibrary" to "jackson",
        )
    )
}

What complied with 7.24.0, fails to compile in 7.25.0 because Serializer.kt is now:


import tools.jackson.databind.DeserializationFeature
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.cfg.DateTimeFeature
import com.fasterxml.jackson.annotation.JsonInclude
import tools.jackson.module.kotlin.jsonMapper
import tools.jackson.module.kotlin.kotlinModule

object Serializer {
    @JvmStatic
    val jacksonObjectMapper: JsonMapper = jsonMapper {
        addModule(kotlinModule())
        changeDefaultPropertyInclusion { it.withValueInclusion(JsonInclude.Include.NON_ABSENT) }
        disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS)
        disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    }
}

Because I explicitly set useJackson3=false, the generated code should import com.fasterxml.jackson

Related issues/PRs

#24709

Suggest a fix

Remove the addition of setUseJackson3(true) as pointed out in https://github.com/OpenAPITools/openapi-generator/pull/24709/changes#r3917417022

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Serializer.kt shown in the report and compare generation with 7.24.0 versus 7.25.0 using the provided Gradle options. Read the change and discussion in related issue or PR #24709, then verify that useJackson3=false produces com.fasterxml.jackson imports and that the generated sources compile with Spring Boot 4 and Jackson 2.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, spring-boot
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.