A KSerializer abstract implementation that encodes and decodes T as a String.

This serializer can be used to serialize non-primitive arguments in navigation keys that are used for deep linking.

Compatible with androidx.compose.runtime.saveable.rememberSerializable, meaning this KSerializer can be used on navigation keys that are saved/restored via androidx.compose.runtime.saveable.rememberSerializable or androidx.navigation3.runtime.rememberNavBackStack

import androidx.navigation3.runtime.deeplink.DeepLinkRequest
import androidx.navigation3.runtime.deeplink.DeepLinkUri
import androidx.navigation3.runtime.deeplink.UriDeepLinkMatcher

val matcher =
    UriDeepLinkMatcher(
        uriPattern =
            DeepLinkUri("http://www.nav3example.com/products?product={product}&count={count}"),
        serializer = serializer<ProductInventoryKey>(),
    )

val request =
    DeepLinkRequest(
        uri = DeepLinkUri("http://www.nav3example.com/products?product=123-productA&count=12")
    )
val startKey = matcher.match(request)?.key ?: HomeKey

Summary

Public constructors

Cmn

Public functions

final T
deserialize(decoder: Decoder)

Decodes the string with the given decoder into a T .

Cmn
abstract T

Decode the given value as a T

Cmn
abstract String
serialize(value: T)

Encode the given value as a String

Cmn
final Unit
serialize(encoder: Encoder, value: T)

Encode the given value as a String with the given encoder.

Cmn

Public properties

final SerialDescriptor
Cmn
abstract String

The unique serial name that identifies the serializable class T

Cmn

Public constructors

DeepLinkSerializer

<T : Any> DeepLinkSerializer()

Public functions

deserialize

final fun deserialize(decoder: Decoder): T

Decodes the string with the given decoder into a T .

deserialize

abstract fun deserialize(value: String): T

Decode the given value as a T

In general, the output of this function will be used as the input of serialize, so their input/output should be compatible.

serialize

abstract fun serialize(value: T): String

Encode the given value as a String

In general, the output of this function will be used as the input of deserialize, so their input/output should be compatible.

serialize

final fun serialize(encoder: Encoder, value: T): Unit

Encode the given value as a String with the given encoder.

Public properties

descriptor

final val descriptorSerialDescriptor

serialName

abstract val serialNameString

The unique serial name that identifies the serializable class T