How do I make this polymorphically serializable? ...
# serialization
a
How do I make this polymorphically serializable?
Copy code
@Serializable
sealed class Result<T> {
    @Serializable
    class Success<T>(val data: T) : Result<T>()

    @Serializable
    class Failure<T>(val msg: String) : Result<T>()
}
So that If I have a class
Copy code
@Serializable
data class Person(val name:String)
I can call
Copy code
Json.stringify(Result.Serializer(Person.serializer()),Result.Success(Person("Andy)))
I have little knowledge in Polymorphic Serialization
k
It's been a while, but that seems correct. I would assume that that would work in 2 directions?
a
It doesn't work. Says
Person is not registered for Polymorphic Serialization
k
Huh, I don't understand why it's saying that.
j
I cannot get it working too, I only can stringify if I get the result success data, but stringify the result is giving me the same errors, even trying adding multiple @Polymorphic annotations to the properties
a
Same here . . .
j
The sealed class is working perfectly with Jake Wharton serializer and a custom adapter for retrofit, maybe there you can see some hint
a
Can I get a link?