Skip to content

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

Description

@pkubowicz

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions