Description
Kotlin client enums generated with the Jackson serialization library are deserialized by ordinal instead of by the numeric value defined in the OpenAPI schema. When a server legitimately returns -1 for an enum whose values
are [-1, 0, 1], Jackson throws InvalidFormatException: index value outside legal index range [0..2].
openapi-generator version
7.17.0 (regression vs Java templates, which already emit the proper annotations)
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Numeric enum repro
version: latest
paths:
/example:
get:
operationId: getExample
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/ExampleModel'
components:
schemas:
ExampleModel:
type: object
required:
- source
properties:
source:
$ref: '#/components/schemas/ExampleNumericEnum'
ExampleNumericEnum:
type: integer
format: int32
enum:
- -1
- 0
- 1
Generation Details
CLI (but same via Gradle/Maven plugin):
openapi-generator-cli generate -g kotlin -i numeric-enum.yaml -o out --library jvm-retrofit2 --additional-properties=serializationLibrary=jackson
Steps to reproduce
- Generate the Kotlin client as above.
- Call the generated API when the server responds with {"source":-1}.
- Observe Jackson throwing InvalidFormatException: index value outside legal index range [0..2] because ExampleNumericEnum lacks @JsonCreator/@jsonvalue.
Related issues/PRs
Suggest a fix
Annotate Kotlin enums the same way the Java templates already do: add @get:JsonValue to the backing value and @JsonCreator @JvmStatic to the factory method so Jackson binds numeric values by value instead of by ordinal.
Description
Kotlin client enums generated with the Jackson serialization library are deserialized by ordinal instead of by the numeric value defined in the OpenAPI schema. When a server legitimately returns -1 for an enum whose values
are [-1, 0, 1], Jackson throws InvalidFormatException: index value outside legal index range [0..2].
openapi-generator version
7.17.0 (regression vs Java templates, which already emit the proper annotations)
OpenAPI declaration file content or url
Generation Details
CLI (but same via Gradle/Maven plugin):
Steps to reproduce
Related issues/PRs
Suggest a fix
Annotate Kotlin enums the same way the Java templates already do: add @get:JsonValue to the backing value and @JsonCreator @JvmStatic to the factory method so Jackson binds numeric values by value instead of by ordinal.