https://kotlinlang.org logo
Title
d

Daniel

04/12/2023, 7:15 AM
Hi. Is there a way to use serialization annotations defined in interface by default by the classes that implement them? If I have something like this:
sealed interface HasA {
    @Serializable(with = CustomSerializer::class)
    @SerialName("custom_a") val a: CustomType
}

@Serializable
data class Entity(
    override val a: CustomType,
    @SerialName("custom_b") val b: Int
) : HasA
I would get error that
a
in
Entity
is not serializable
if you only need a single property and can change your class structure to wrap instead of inherit, https://github.com/Kotlin/kotlinx.serialization/issues/292#issuecomment-1130158185 may be a workaround
d

Daniel

04/12/2023, 8:03 AM
That seems like something that might be potentially solvable with the experimental
InheritableSerialInfo
🤔 https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-inheritable-serial-info/