Navigation Kotlinx Serialization
This optional JVM 11 adapter creates a Core NavRouteSpec<T> from a Kotlinx KSerializer<T>. The
source-registered 0.1.0-alpha01 exposes Navigation Core and Serialization Core, has no platform
dependencies, and is intended for flat route schemas.
Create a route spec
@Serializable
data class ProfileRoute(
val userId: Long,
val tab: String = "posts",
)
val ProfileDestination: NavRouteSpec<ProfileRoute> =
serializableNavRouteSpec(name = "profile")
fun serializableRouteSample(): ProfileRoute {
val route = ProfileDestination.encode(ProfileRoute(userId = 42L))
return ProfileDestination.decode(route)
}
The reified overload obtains the serializer; other callers pass it. Exact mapping is Boolean to
BooleanValue, Byte/Short/Int to IntValue, Long to LongValue, Float/Double to their matching
value, Char/String/enum to Text, and nullable scalars to their value or Null.
The root must be a class or object with scalar, enum, nullable-scalar, or supported inline-scalar
fields. Construction rejects nested objects, collections, maps, polymorphic/contextual shapes,
unsigned fields, non-object roots, and non-finite floats. Call-local JSON bridges the serializer;
only immutable NavRoute/NavValue is retained. Decode rejects unknown names, invalid nulls, and
wrong variants; omitted defaults are reconstructed. Keep schema restore-compatible; alternative
JSON names are disabled.
See Navigation Core, architecture, Compose migration, and the generated API.