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
Dominaezzz
05/06/2020, 2:59 PM
The simple answer is erased generics are hard to deal with.
Dominaezzz
05/06/2020, 3:00 PM
For a solution, do you actually need
Response
to be generic?
Dominaezzz
05/06/2020, 3:00 PM
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()
}