I was able to resolve the issue I was facing with the kotlinx.serialization.SerializationException. After some troubleshooting, I discovered the root of the problem was related to two things:
Initialization of the route class: I needed to ensure that the route class is initialized with default or null values.
Setting the correct startDestination in the nested navigation graph: I had to use GroupDetail() as the startDestination when defining the navigation graph.
Solution Step 1: Initialize the Route Class with Default/Null Values
The first issue was with the initialization of my route. I needed to ensure that GroupDetail was initialized with null or default values when declaring the start destination in the navigation graph.
@Serializable
data class GroupDetail(val id: String? = null)
Step 2: Define Nested Graph with Correct startDestination
In my nested graph, I was missing the proper initialization of the startDestination. The solution was to ensure that GroupDetail() (with null/default values) was passed as the startDestination.
Here’s the updated navigation setup:
fun NavGraphBuilder.groupDetailNavGraph(rootNavController: NavHostController) {
navigation<GroupDetailGraph>(
startDestination = GroupDetail() // Ensure to use GroupDetail() here
) {
composable<GroupDetail> { backStackEntry ->
val group: GroupDetail = backStackEntry.toRoute()
GroupDetailScreen(rootNavController = rootNavController)
}
}
}