kotlinx serialization. Deserialize generic parameter trouble

313 Views Asked by At

I am migrating my project serialization client from GSON to KotlinxSerialization and Faced a problem: All responses from API inherit an abstraction class for example:

abstract class BaseResponse <T> (
val type: String? = null,
val payload: T? = null){

When I try to get a response from the API, I use the class

@Srializable
class LoginResponse: BaseResponse <LoginResponse.LoginPayload> (){

class LoginPayload(val s: Int)

}

and getting serialization error java.lang.NoSuchFieldError: No field typeSerial0 of type Lkotlinx / serialization / KSerializer; in class Lru / .../ response / LoginResponse $$ serializer; or its superclasses

As I understand it, the deserializer tries to deserialize the fields of the parent class first and does not understand how to deserialize the payload. Spent two days on this problem, and I don't know how to solve it.

0

There are 0 best solutions below