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" ) : KSerializer> class ServiceResultSurrogate( In Kotlin, these are called data classes and are marked with data: data. = ServiceResultSerializer::class)ĭata class Success(val data: T) : ServiceResult()ĭata class Error(val exceptionMessage: String?) : ServiceResult() Gob is an encoding / decoding tool for serialization of data structures in the. For the sake of simplicity in the example I only represent the exception message. 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.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |