Paulius Ruminas
07/16/2019, 6:33 PMPolymorphicSerializer
for sealed class like this
@Serializable(PolymorphicSerializer::class)
sealed class Response {
@Serializable
data class Success(val token: Token) : Response()
// serializer defined in serial module
object Failure : Response()
}
I found this section in doc comment of @Polymorphic
annotation.
Does not affect sealed classes, because they are gonna be serialized with subclasses automatically with special compiler plugin support which would be added later.
At first I thought I could use @Polymorphic
instead of @Serializable(PolymorphicSerializer::class)
but it does not work that way.
Will this approach change in the future?sandwwraith
07/17/2019, 9:12 AMDoes not affect...
means you can't annotate @Polymorphic sealed class Response
, but can annotate it on use site: @Polymorphic val resp: Response
sandwwraith
07/17/2019, 9:13 AMPaulius Ruminas
07/17/2019, 9:15 AMYes, sealed classes would be automatically polymorphic in futureThat mean it will implicitly use
PolymorphicSerializer
and it will not be required to add @Serializable(PolymorphicSerializer::class)
to the sealed class?sandwwraith
07/17/2019, 9:16 AMSerialModule
pdvrieze
07/17/2019, 9:42 AMEncoder.encodeSerializableValue()
and friends (at least overloaded methods, let's keep binary compatibility).