kotlinx.serialization
kotlinx.serialization copied to clipboard
Support field renaming within parent classes/interfaces
What is your use-case and why do you need this feature? Currently, one need to rename every implemented field of a parent class/interface:
interface Project {
val name: String
val originalTime: Long
}
@Serializable
class OwnedProject(
@SerialName("custom_name")
override val name: String,
@SerialName("original_t")
override val originalTime: String
) : Project
@Serializable
class OtherProject(
@SerialName("custom_name")
override val name: String,
@SerialName("original_t")
override val originalTime: String,
val other: String
) : Project
Describe the solution you'd like
It should be able to use @SerialName on parent fields:
interface Project {
@SerialName("custom_name")
val name: String
@SerialName("original_t")
val originalTime: Long
}
@Serializable
class OwnedProject(
override val name: String,
override val originalTime: String
) : Project
@Serializable
class OtherProject(
override val name: String,
override val originalTime: String,
val other: String
) : Project
I think other Annotations like Transient and Required etc. should be inherited as well
Related comment: https://github.com/Kotlin/kotlinx.serialization/issues/1950#issuecomment-1362986792