[kotlin] register service-loaded Jackson modules with useJackson3

KD
2mo ago
+24-0

The Jackson 2 branch of Serializer.kt.mustache calls findAndRegisterModules(), so modules published via META-INF/services are registered. The Jackson 3 branch added in #24709 only calls addModule(kotlinModule()), so they are silently dropped.

Measured with jackson-databind 3.1.5 and jackson-databind-nullable:0.2.11, which ships that service file:

  • JsonMapper.builder().build() -> {"name":{"present":true,"undefined":false}}
  • .findAndAddModules().build() -> {"name":"x"}

Adding a module explicitly and by discovery registers it once, so addModule(kotlinModule()) stays.

Both jackson3 samples regenerated; ./gradlew compileKotlin on kotlin-jackson3 passes. The new test fails on master.

Fixes #24859

/cc @jimschubert @stefankoppier


Summary by cubic

Registers service-loaded Jackson modules when generating Kotlin clients with useJackson3, fixing #24859.

The Jackson 3 branch of Serializer.kt only added the Kotlin module, so third-party modules published via META-INF/services were silently dropped. It now calls findAndAddModules() to match Jackson 2 behavior. Explicit module registration is still deduplicated, so addModule(kotlinModule()) remains.