NavKeySerializer
A KSerializer for handling polymorphic NavKey hierarchies on Android.
This serializer enables kotlinx.serialization to save and restore different disparate implementations of NavKey without requiring developers to manually register them in a SerializersModule.
How It Works
Instead of serializing the NavKey directly, this class serializes two pieces of information:
The fully qualified class name of the concrete NavKey (e.g., "com.example.Home").
The actual
NavKeyobject, using its specific runtime serializer.
During deserialization, it reads the class name first, uses reflection (Class.forName) to find the corresponding KSerializer for that class, and then uses that serializer to deserialize the object data.
Platform Limitation
This serializer is for Android only. It relies on JVM reflection (Class.forName) which is not available on other platforms in a multiplatform context.
Type Parameters
The base NavKey type this serializer can handle.