-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrecr generic sealed-class polymorhic serializer plugin #2729
Comments
In general, we do not support serialization to/from |
I do not mean use Any. I use generic parameter, very well known at the time of usage. It actually works if I won't use sealed class polymorphism, in the code above, serializing still-generic type val y = CTest.AsList(listOf(1,2,3))
println(Json.encodeToString(y)) //> {"c":[1,2,3]} Why it works with |
@sergeych I think I know what is going on. The type of What would need to happen is for the plugin to generate the |
@pdvrieze I think you are right, it explains everything. Dear maintainers, please fix the plugin to properly serialize generic sealed-class polymorphism? Right now it is not working with generic types which is not good. We need it to make real use of the kotinx serialization. Which is by far the only maintained KMP serialization I know. |
I think it was already discussed in #2555 In short, A in @Serializable
sealed class CTest<A> {
abstract val c: Collection<A>
@Serializable
class IntList(override val c: List<Int>) : CTest<Int>()
} |
When I'm calling deserializer, I provide it with a specific type: Even if it can't, the klutch could be used to specify serializer subtypes manually, like
It is ugly but better than nothing. Insofar sealed-class polymorphism with generic types is not working further than samples, and when I've tried to write own intelligent serializer for close-type hierarchies I found that most of it mechanics is concealed and not available outside. Not to mention that it is very sparsely documented. So, if you see no way to improve the plugin (the point where you know for sure actual types), maybe you'll leave us a way to specify types by hand? |
The following code fails on compilation:
with strange error text:
To Reproduce
code snippet above.
Expected behavior
either correct serialization or correct error message. To be clear: Int serializer exists, and should not be requested
to be re-declared in anyway, especially in the Any, and Any should not be requested to be made sealed ;)
If such serialization can't be done automatically, please describe how it can be done by hand; i tried CTest.serializer(Int...) but
it did not help with the same error.
Environment
The text was updated successfully, but these errors were encountered: