Is your feature request related to a problem? Please describe.
The kotlin-spring generator adds = null to all optional properties in data classes:
data class UserDto(
val name: String,
val email: String? = null,
val role: RoleEnum? = null
)
This causes two problems:
- Silent data loss at scale. In projects with hundreds of models, default = null lets
callers omit fields without any compiler warning. When a new field is added, every existing
call site compiles fine and the missing field goes unnoticed until production.
- Incorrect behavior with some libraries. Tools like MapStruct don't handle Kotlin default
values correctly, leading to bugs in mapping logic.
Describe the solution you'd like
A config option (e.g. ommitDefaultNullValues) that omits = null defaults for optional
properties:
data class UserDto(
val name: String,
val email: String?,
val role: RoleEnum?
)
Implementation:
#23077
a switch in KotlinSpringServerCodegen.java + conditional wrap in
dataClassOptVar.mustache.
Describe alternatives you've considered
- Custom templates (--template-dir): works but requires maintaining a template fork across
upgrades.
Is your feature request related to a problem? Please describe.
The kotlin-spring generator adds = null to all optional properties in data classes:
This causes two problems:
callers omit fields without any compiler warning. When a new field is added, every existing
call site compiles fine and the missing field goes unnoticed until production.
values correctly, leading to bugs in mapping logic.
Describe the solution you'd like
A config option (e.g. ommitDefaultNullValues) that omits = null defaults for optional
properties:
Implementation:
#23077
a switch in KotlinSpringServerCodegen.java + conditional wrap in
dataClassOptVar.mustache.
Describe alternatives you've considered
upgrades.