Hello guys, I am having a challenge with returning my response sealed class. I think is something to do with serialization but haven't been able to figure it out yet.
My error: Problem retrieving User.Try again later!
Serializer for class 'Success' is not found. Mark the class as @Serializable or provide the serializer explicitly.
Here is my sealed class.
Copy code
@Serializable
sealed class Resource<T>(
val data: T? = null,
val message: String? = null,
val token: String? = null
) {
class Success<T>(data: T?, message: String, token: String? = null) :
Resource<T>(data, message, token)
class Error<T>(message: String, data: T? = null, token: String? = null) :
Resource<T>(data, message, token)
}
a
Aleksei Tirman [JB]
07/21/2022, 6:42 AM
You can rewrite your serializable classes in the following way to make it work:
Copy code
@Serializable
sealed class Resource {
@Serializable
class Success<T>(val data: T, val token: String? = null) : Resource()
@Serializable
class Error(val message: String, val token: String? = null) : Resource()
}
p
phldavies
07/21/2022, 10:00 AM
@Serializable
annotation is not inherited for subclasses/objects