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

Polymorphic using both explicit definition and sealed implicit lookup #2199

Open
hrach opened this issue Feb 20, 2023 · 1 comment
Open

Polymorphic using both explicit definition and sealed implicit lookup #2199

hrach opened this issue Feb 20, 2023 · 1 comment
Labels

Comments

@hrach
Copy link

hrach commented Feb 20, 2023

I have a library that exposes the interface Destination and an API accepting this Destination - I need the library to be able to process all destinations with KotlinX.Serialization.

I have a user-land app that defines multiple destinations and joins them via a sealed interface.

package library

interface Destination

package app

@Serializable
sealed interface AppDestination : Destination {
   @Serializable
   object One : AppDestination

   @Serializable
   object Two : AppDestination
}

To be able to pass e.g. AppDestination.One to API accepting Destination, I must explicitly wire them together:

serializersModule = SerializersModule {
	polymorphic(Destination::class) {
		subclass(serializer<AppDestination.One>())
		subclass(serializer<AppDestination.Two>())
	}
}

I'd like to be able to utilize the sealed interface and just call the subclass for AppDestination

serializersModule = SerializersModule {
	polymorphic(Destination::class) {
		subclass(serializer<AppDestination>())
	}
}

Use case: https://github.com/kiwicom/navigation-compose-typed

@hrach hrach added the feature label Feb 20, 2023
@sandwwraith
Copy link
Member

Related: #1865

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

No branches or pull requests

2 participants