Skip to content
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

Sealed interface @Serializable support #1576

Closed
y9san9 opened this issue Jun 29, 2021 · 5 comments
Closed

Sealed interface @Serializable support #1576

y9san9 opened this issue Jun 29, 2021 · 5 comments
Assignees

Comments

@y9san9
Copy link

y9san9 commented Jun 29, 2021

I don't know if it is a bug but just wanted to ask, why can I do abstract val stuff with sealed classes but can't do the same thing with interfaces.
image
image

@pdvrieze
Copy link
Contributor

In general, interfaces can not be marked serializable. However sealed interfaces are sort of an exception. However sealed interfaces are a new feature, so I suspect it is not implemented yet in the compiler plugin.

@y9san9
Copy link
Author

y9san9 commented Jun 30, 2021

Then the issue is actual, waiting for implementation 🙃

@sandwwraith
Copy link
Member

sealed interfaces are currently treated as regular interfaces (can't have serializable annotation and require serializers module). In the future, yes, @Serializable annotation on sealed interfaces would be supported

@PaulWoitaschek
Copy link
Contributor

And this feature is tracked here? Is there a roadmap for it?
Currently when I only need sealed to get compile time safety I go with sealed interfaces over classes, but whenever I need sth to be serializable I now need to go back to sealed classes.

zhelenskiy pushed a commit to JetBrains/kotlin that referenced this issue Dec 6, 2021
Interfaces (regular and sealed) are by default polymorphic. To benefit
from sealing (i.e. knowledge of all inheritors in compile-time), @serializable
annotation may be added on sealed interface, generating the same serializer
that can be used for sealed classes.

Synthetic nested classes are not generated in DEFAULT_IMPLS mode because
it causes problems when adding a synthetic companion to an interface.

Fixes Kotlin/kotlinx.serialization#1576
@LouisCAD
Copy link
Contributor

Is this supported for protobuf too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants