[BUG][KOTLIN] Jackson3 option does not discover modules like Jackson2 does

Open Beginner friendly
#24,859 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start with kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache and compare the useJackson3 block with the Jackson 2 output generated when useJackson3 is false. Generate a jvm-spring-restclient client using the reported options, then verify that Jackson 3 discovers classpath modules such as JsonNullableJackson3Module and handles JsonNullable fields correctly.

Written by the indexing model from the issue text.

Description

Issue: Bug
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

Serializer generated with useJackson3: true is different from the one generated for Jackson 2: it does not load modules.

Any third-party Jackson 3 module on the classpath is silently ignored. Concrete case: org.openapitools:jackson-databind-nullable:0.2.11 ships META-INF/services/tools.jackson.databind.JacksonModule → JsonNullableJackson3Module, which never gets registered, so JsonNullable fields serialize/deserialize wrongly

openapi-generator version

7.25.0; not a regression, rather a bug in a new feature added in #24709

OpenAPI declaration file content or url

N/A (the bug is in the infrastructure code, not in models)

Generation Details
eneratorName: kotlin
  configOptions: 
    library: jvm-spring-restclient
    serializationLibrary: jackson
    useSpringBoot3: true
    useSpringBoot4: true
    useJackson3: true
Steps to reproduce

Open <pkg>/infrastructure/Serializer.kt

Actual:

 val jacksonObjectMapper: JsonMapper = jsonMapper {
      addModule(kotlinModule())
      ...
  }

Expected: parity with the Jackson 2 output, which is generated from the same template with
useJackson3: false

 val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
      .findAndRegisterModules()
      ...
Related issues/PRs

#24709

Suggest a fix

Change kotlin-client/jvm-common/infrastructure/Serializer.kt.mustache; add findAndAddModules() as the first line of the {{#useJackson3}} jsonMapper { … } block.

Dominant language
Java
Stars
26.8k
Forks
7.7k
Avg merge
1d 10h
Merged PRs (30d)
103

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.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.