Is it possible to use nested Serializable in Compo...
# compose
a
Is it possible to use nested Serializable in Compose type safe navigation? I tried it once but got the error. If not is it being tracked in some issue?
h
@Atul Gupta It is not supported ig
a
What do you want to achieve with nested Serializables here?
h
Ig he wants to send a data class as params while navigation. I had the same use-case but it somehow didn't worked 😅
s
Might be worth showing what you tried and didn't work so far. We use many serializable data classes that themselves have children data classes that are also serializable and so on, but it may work because of the way we did it.
a
I am getting the below error
Copy code
java.lang.IllegalArgumentException: Cannot cast name of type Model to a NavType. Make sure to provide custom NavType for this argument.
My destination model is
Copy code
@Serializable
data class Model(val id: String)

@Serializable
data class ParentModel(val id: String, val name: Model)
I think at
internal fun SerialDescriptor.getNavType(): NavType<*>
there is no handling of
Serializable
type
s
Well, what are you passing to the typeMap parameter?
a
Hi @Stylianos Gakis I have updated the code to include the
Model
class as well, both are
@Serializable
, also I didn't get what do you mean by
typeMap
s
Take a look at this https://medium.com/androiddevelopers/navigation-compose-meet-type-safety-e081fb3cf2f8 If you have custom parameters, you need to create your own NavType and pass it to your composable destination in the
typeMap
parameter