Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type safe navigation with custom NavType

This is model I am using for navigation in Android Compose

@Serializable
sealed class Routes {
    @Serializable
    data class Route1() : Routes()

    @Serializable
    data class Route2(
        val nextRoute: Routes,
        val backRoute: Routes
    ) : Routes()

    @Serializable
    data class Route3() : Routes()
}

unfortunatelly I get error: java.lang.IllegalArgumentException: Route Routes.Route2 could not find any NavType for argument nextRoute of type Routes - typeMap received was {} I have seen some examples of writing a customTypes for serializations - https://medium.com/mercadona-tech/type-safety-in-navigation-compose-23c03e3d74a5 But this is a special case.

like image 805
maxxxo Avatar asked Dec 08 '25 16:12

maxxxo


1 Answers

It appears nested objects are not supported (yet?), flattening the object to only contain json primitives seems to work.

like image 102
user1126068 Avatar answered Dec 10 '25 23:12

user1126068



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!