writingose.blogg.se

Kotlin data class serializable
Kotlin data class serializable









kotlin data class serializable

Override val descriptor: SerialDescriptor = surrogateSerializer. Private val surrogateSerializer = rializer(tSerializer) for "Error" data: T? = exceptionMessage: String? = null The annotation is not necessary, but it avoids serializing "data = null" to view the data from the database public void view(String name) throws. ) : KSerializer> class ServiceResultSurrogate( If singleton class is Serializable, you can serialize the singleton instance.

kotlin data class serializable

= ServiceResultSerializer::class)ĭata class Success(val data: T) : ServiceResult()ĭata class Error(val exceptionMessage: String?) : ServiceResult() For the sake of simplicity in the example I only represent the exception message.

kotlin data class serializable

As Animesh Sahu already mentioned there is an issue for this topic that is still open, but the solution using a surrogate suggested by Михаил Нафталь for serialization of Error can actually be used also to serialize the polymorphic ServiceResult, by creating a surrogate that mixes the fields of Success and Error.











Kotlin data class serializable