Bug Report Checklist
Description
PR #22535 introduced a breaking change in v7.18.0 for the Kotlin client generator with Jackson serialization. The change added @JsonCreator annotation to the decode() companion function in enum classes, which causes invalid enum values to be silently converted to null instead of throwing an exception.
This breaks:
- Input validation - Invalid enum values are silently accepted
- Error messages - No exception is thrown for invalid data
- Distinguishing null/absent/invalid - All three cases now result in null
- ObjectMapper configuration - DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL is bypassed
The Kotlin client template doesn't implement the same conditional logic as Java. The Java template respects isNullable and enumUnknownDefaultCase options, while Kotlin always returns null for unknown values.
openapi-generator version
- Broken: 7.18.0
- Working: 7.17.0
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Enum Test API
version: "1.0.0"
paths:
/test:
post:
operationId: testEndpoint
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/MyRequest'
responses:
'200':
description: OK
components:
schemas:
MyEnumType:
type: string
description: An example enum type
enum:
- VALUE_A
- VALUE_B
- VALUE_C
MyRequest:
type: object
properties:
status:
$ref: '#/components/schemas/MyEnumType'
Generation Details
Generate a Kotlin client with Jackson serialization using the spec above:
openapi-generator-cli generate \
-i spec.yaml \
-g kotlin \
--additional-properties=serializationLibrary=jackson \
-o output/
Steps to reproduce
- Generate Kotlin client code using the command above
- Look at the generated enum class (e.g., MyEnumType.kt) - note the decode() function with @JsonCreator uses firstOrNull which returns null for unknown values
- In your application, deserialize JSON with an invalid enum value:
val mapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
val json = """{"status":"INVALID_VALUE"}"""
val result = mapper.readValue<MyRequest>(json)
// Expected: throws exception
// Actual: result.status == null (silent failure)
- v7.17.0: Jackson uses default enum deserialization → throws InvalidFormatException
- v7.18.0: Jackson uses @JsonCreator decode() → silently returns null
Related issues/PRs
The Java generator went through the same discussion in #625 and established that:
- Default behavior: Throw
IllegalArgumentException for unknown enum values
- Option
enumUnknownDefaultCase: Return a default value if enabled
- Nullable handling: Return null only if the schema allows nullable
Suggest a fix
Modify modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache to match Java's conditional logic
Bug Report Checklist
Description
PR #22535 introduced a breaking change in v7.18.0 for the Kotlin client generator with Jackson serialization. The change added @JsonCreator annotation to the decode() companion function in enum classes, which causes invalid enum values to be silently converted to null instead of throwing an exception.
This breaks:
The Kotlin client template doesn't implement the same conditional logic as Java. The Java template respects isNullable and enumUnknownDefaultCase options, while Kotlin always returns null for unknown values.
openapi-generator version
OpenAPI declaration file content or url
Generation Details
Generate a Kotlin client with Jackson serialization using the spec above:
openapi-generator-cli generate \ -i spec.yaml \ -g kotlin \ --additional-properties=serializationLibrary=jackson \ -o output/Steps to reproduce
Related issues/PRs
The Java generator went through the same discussion in #625 and established that:
IllegalArgumentExceptionfor unknown enum valuesenumUnknownDefaultCase: Return a default value if enabledSuggest a fix
Modify modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache to match Java's conditional logic