https://kotlinlang.org logo
#serialization
Title
# serialization
j

Jon Bailey

11/29/2023, 6:53 PM
Hi, is there a way to have @SerialName inherited? I have a sealed interface (I've tried sealed class too) like below, and would rather avoid duplicating
has_available_stock
in each data class. My only option so far is to have a const val but that seems less ideal.
Copy code
@Serializable
internal sealed interface Foo {
    @SerialName("has_available_stock")
    val hasAvailableStock: Boolean

    @Serializable
    data class Foo1(
        override val hasAvailableStock: Boolean
    ) : Foo

    @Serializable
    data class Foo2(
        override val hasAvailableStock: Boolean
    ) : Foo
}
e

ephemient

11/29/2023, 7:25 PM
in this particular case,
Copy code
Json { namingStrategy = JsonNamingStrategy.Builtins.SnakeCase }