I have another question :smirk: Using polymorphism...
# serialization
d
I have another question 😏 Using polymorphism AND generics
Copy code
@Serializable
sealed class Response<T> {
    @Serializable
    data class ResponseData<T>(
        @SerialName("data")
        val data: T
    ) : Response<T>()

    @Serializable
    data class AuthData(
        @SerialName("data")
        val data: AdditionalAuthorization?
    ) : Response<AdditionalAuthorization?>()
}
I get this error
Copy code
Unexpected JSON token at offset 0: Expected '[, kind: SEALED'.
It fails even with the simplest json. Apart from sealed classes I've also tried interface, open, abstract - same error, different kind given in message. Is what I'm trying to achieve supported by kotlinx.serialization?
d
The simple answer is erased generics are hard to deal with.
For a solution, do you actually need
Response
to be generic?
Copy code
@Serializable
sealed class Response {
    @Serializable
    data class ResponseData<T>(
        @SerialName("data")
        val data: T
    ) : Response()

   @Serializable
    data class AuthData(
        @SerialName("data")
        val data: AdditionalAuthorization?
    ) : Response()
}