You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, encodeDefaults = true writes all default values, while encodeDefaults = false omits all of them.
There is no way to include only non-null defaults.
Motivation
In many API contexts, it is desirable to serialize default values that carry meaningful information but skip those that are null by default.
This keeps payloads compact and avoids sending meaningless null entries while still preserving useful defaults.
@Serializable
data class UserProfile(
val id: String,
val nickname: String?,
val displayName: String? = null,
val country: String = "DE",
val avatarUrl: String? = null,
)
Rationale:
This would allow developers to keep meaningful defaults (like "DE") while automatically skipping null defaults, avoiding the need for custom serializers or post-processing.