Dave Leeds
07/06/2025, 7:17 PM@Serializable
@JvmInline
value class Id(val value: String)
... as part of a route class like this ...
@Serializable
data class Document(val id: Id)
Then I get an error when trying to navigate with it.
DocumentListScreen(onDocumentClicked = { id -> nav.navigate(Document(id)) })
Here's what the error looks like:
Route Document could not find any NavType for argument id of type Id - typeMap received was {}
I've worked around this by unwrapping the value.
DocumentListScreen(onDocumentClicked = { id -> nav.navigate(Document(id.value)) })
And then reinstantiating the Id
value class on the other side. But I'm wondering whether I'm doing things right. Is there a more appropriate way to make this work? I'd love to keep using value classes for things like this if possible.Lukáš Kúšik
07/06/2025, 9:30 PMcomposable<Screen.Theme>(typeMap) {
ThemeScreen(navController)
}
private val typeMap = mapOf(
typeOf<Uuid>() to serializableNavType(Uuid.serializer()),
)
//example with inline fun <reified T> serializableNavType...
although I would have hoped that the value class would get inlined to String and everything would work by defaultDave Leeds
07/07/2025, 12:24 AM