-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
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. skipDefaultValues) that omits = null defaults for optional
properties:
data class UserDto(
val name: String,
val email: String?,
val role: RoleEnum?
)Implementation:
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.
Reactions are currently unavailable