[kotlin] Add @get:JsonValue to nested Jackson enums (#23886)#24047
[kotlin] Add @get:JsonValue to nested Jackson enums (#23886)#24047seonwooj0810 wants to merge 1 commit into
Conversation
c5f72f7 to
517a61f
Compare
Nested (inline) enum classes generated into Kotlin data classes were missing the @get:JsonValue annotation that top-level enum classes already carry. Without it, Jackson serializes an Int-valued nested enum by its constant name instead of its numeric value, producing wrong JSON output. Add @get:JsonValue (and the JsonValue import, guarded by hasEnums) to the nested enum declaration in the kotlin-client data_class template, mirroring enum_class.mustache. Regenerate affected Kotlin Jackson client samples and add a regression test. Fixes OpenAPITools#23886
517a61f to
675af99
Compare
|
Rebased onto master; jackson kotlin samples regenerated and The only red check, |
|
The only red check here — This PR only touches the kotlin Jackson templates/samples — it doesn't touch the okhttp4/moshi sample, and |
Fixes #23886
Problem
For the Kotlin client generator with
serializationLibrary=jackson, nested (inline) enum classes generated into a model's data class are missing the@get:JsonValueannotation that top-level enum classes already carry (enum_class.mustache). Without it, Jackson serializes anInt-valued nested enum by its constant name instead of its numeric value, producing wrong JSON output (a string where a number is expected).Change
kotlin-client/data_class.mustache: add{{#jackson}}@get:JsonValue {{/jackson}}to the nestedenum classdeclaration, mirroringenum_class.mustache, and importcom.fasterxml.jackson.annotation.JsonValue(guarded by{{#hasEnums}}) so the generated code compiles.KotlinClientCodegenModelTest#testJacksonNestedEnumsUseJsonValuewith specissue23886-kotlin-nested-numeric-enum.yaml../bin/generate-samples.shfor thekotlin-clientjackson configs). All sample changes are limited to the added@get:JsonValueand theJsonValueimport.Test evidence
Verification done: confirmed the gap on
master(top-levelenum_class.mustacheemits@get:JsonValuewhile nested enums indata_class.mustachedid not); confirmed no in-flight PR / claim on #23886; the diff across all 24 regenerated sample files contains only the new annotation/import lines.PR checklist
./bin/generate-samples.shfor the affectedkotlin-clientjackson configs and committed all changed files.masterbranch.@jimschubert @stefankoppier — Kotlin technical committee, this touches the
kotlin-clientenum template and thejvm-spring-webclient/jvm-spring-restclientsamples.Summary by cubic
Adds
@get:JsonValueto nested enum value parameters in Kotlin Jackson client models so Jackson serializes by value (e.g., numbers) instead of enum name. Aligns nested enums with top‑level behavior and fixes #23886.kotlin-client/data_class.mustache: add@get:JsonValueto nested enumvalue; importcom.fasterxml.jackson.annotation.JsonValueguarded by{{#hasEnums}}.KotlinClientCodegenModelTest#testJacksonNestedEnumsUseJsonValueusingissue23886-kotlin-nested-numeric-enum.yaml.Written for commit 675af99. Summary will update on new commits.