Skip to content

[FEATURE] Allow defining a sealed class as a subclass of an open polymorphic class #2782

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
rocketraman opened this issue Aug 14, 2024 · 2 comments
Labels

Comments

@rocketraman
Copy link

What is your use-case and why do you need this feature?

I have an open interface, say MyOpenInterface.

I have an implementation of this open interface which is sealed i.e. sealed class MySealed: MyOpenInterface { ... }.

Currently, it seems the only way to define the SerializersModule is to explicitly list all the subtypes of the sealed class:

polymorphic(MyOpenInterface::class) {
  subclass(MySealedSub1::class)
  subclass(MySealedSub2::class)
  ...
}

This was raised on Slack, but no alternative options were provided by anyone.

Describe the solution you'd like

I would like to define a SerializersModule as follows, which would make the module type-safe:

polymorphic(MyOpenInterface::class) {
  subclass(MySealed::class)
}

At the moment, attempting to do this results in an error like this:

Serializer for MySealed can't be registered as a subclass for polymorphic serialization because its kind SEALED is not concrete. To work with multiple hierarchies, register it as a base class.
@pdvrieze
Copy link
Contributor

Would this match pull request #2201 ? I could try to refresh/rebase the pull request.

@rocketraman
Copy link
Author

Would this match pull request #2201 ? I could try to refresh/rebase the pull request.

@pdvrieze Yes, I believe it would.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants