NavKeySerializer

open class NavKeySerializer<T : NavKey> : KSerializer<T>

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:

  1. The fully qualified class name of the concrete NavKey (e.g., "com.example.Home").

  2. The actual NavKey object, 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

T

The base NavKey type this serializer can handle.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): T

Deserializes a concrete NavKey implementation.

Link copied to clipboard
open override fun serialize(encoder: Encoder, value: T)

Serializes a concrete NavKey implementation.