hello there, is there a way to serialize this with...
# serialization
a
hello there, is there a way to serialize this without using a custom serializer?
Copy code
@Serializable
sealed class InfoResults<out T> {
    @Serializable
    data class Shared<out T>(val data: T) : InfoResults<T>()

    @Serializable
    data class NotShared(val message: String) : InfoResults<Nothing>()
}
r
Shouldn't there be properties to serialize?
I mean. As it is, InfoResults doesn't have to be Serializable. It doesn't contain any properties to serialize.
a
Shouldn't there be properties to serialize?
No. It is not a must for there to be properties for it to be serializable.
As it is, InfoResults doesn't have to be Serializable. It doesn't contain any properties to serialize.
If
InfoResults
is not marked as serializable, I can't successfully call
Json.encodeToString<InfoResults<String>>(ir)
The direct problem here is the Nothing argument in
NotShared
case
p
r
I have a sealed class type like that that has a
Nothing
type parameter on one of its subclasses, and it serializes without problem. I think the difference may be that my equivalent of
NotShared
is an
object
.
a
which version of serialization are you using? @rocketraman
r
1.6.10
a
@Petter Måhlén that is what I do need, however I am still getting errors even with the '@NotSerializable' workaround
@rocketraman I am on kotlin 1.6.20-RC with serialization 1.3.2 and it is still failing. Can I just see the portion of your code that works?
r
Sent you a DM
a
Thanks a lot for the help @rocketraman