Good afternoon everyone... I have an issue with Ko...
# android
t
Good afternoon everyone... I have an issue with Kotlin serialisation in my android application
I have this sealed class
@Serializable
sealed class Outcome
@Serializable
object Accepted : Outcome()
@Serializable
object Declined : Outcome()
@Serializable
object Extant : Outcome()
@Serializable
object Extinct : Outcome()
@Serializable
object Success : Outcome()
@Serializable
object Empty : Outcome()
@Serializable
object Failure : Outcome()
when I attempt to encode to string with this statement I get nothing
Copy code
json.encodeToString(Accepted)
where json =
kotlinx.serialization.json.Json
where have I gone wrong???
when I store these values in my Room database I get json resembling
{"type":"<http://org.my|org.my>.package.Accepted"}
e
Copy code
json.encodeToString(Outcome.serializer(), Accepted)
the class discriminator isn't produced by
Accepted.serializer()
, it comes from the polymorphic (sealed class) serializer
t
thankyou very much
e
also for future reference, you can ask questions about kotlinx.serialization in #serialization - it's not Android-specific
👍 1