SavedStateEncoderKt
public final class SavedStateEncoderKt
Summary
Public methods |
|
|---|---|
static final @NonNull SavedState |
<T extends Object> encodeToSavedStateNullable(Serializes the |
static final @NonNull SavedState |
<T extends Object> encodeToSavedStateNullable(Serializes and encodes the given |
Public methods
encodeToSavedStateNullable
public static final @NonNull SavedState <T extends Object> encodeToSavedStateNullable(
@NonNull T value,
@NonNull SavedStateConfiguration configuration
)
Serializes the value of type T into an equivalent SavedState using KSerializer retrieved from the reified type parameter.
Format not stable: The internal structure of the returned SavedState is subject to change in future releases for optimization. While it is guaranteed to be compatible with decodeFromSavedState, direct manipulation of its encoded format using keys is not recommended.
import androidx.savedstate.serialization.encodeToSavedState @Serializable data class User(val id: Int, val name: String) val user = User(123, "foo") val savedState = encodeToSavedState(user)
| Parameters | |
|---|---|
@NonNull T value |
The serializable object to encode. |
@NonNull SavedStateConfiguration configuration |
The |
| Returns | |
|---|---|
@NonNull SavedState |
The encoded |
| Throws | |
|---|---|
SerializationException |
in case of any encoding-specific error. |
| See also | |
|---|---|
decodeFromSavedState |
encodeToSavedStateNullable
public static final @NonNull SavedState <T extends Object> encodeToSavedStateNullable(
@NonNull <Error class: unknown class><@NonNull T> serializer,
@NonNull T value,
@NonNull SavedStateConfiguration configuration
)
Serializes and encodes the given value to SavedState using the given serializer.
Format not stable: The internal structure of the returned SavedState is subject to change in future releases for optimization. While it is guaranteed to be compatible with decodeFromSavedState, direct manipulation of its encoded format using keys is not recommended.
import androidx.savedstate.serialization.SavedStateConfiguration import androidx.savedstate.serialization.encodeToSavedState val config = SavedStateConfiguration { serializersModule = SerializersModule { polymorphic(Any::class) { subclass(String::class) } } } val value = "foo" val encoded = encodeToSavedState( serializer = PolymorphicSerializer(Any::class), value = value, configuration = config, )
| Parameters | |
|---|---|
@NonNull <Error class: unknown class><@NonNull T> serializer |
The serializer to use. |
@NonNull T value |
The serializable object to encode. |
@NonNull SavedStateConfiguration configuration |
The |
| Returns | |
|---|---|
@NonNull SavedState |
The encoded |
| Throws | |
|---|---|
SerializationException |
in case of any encoding-specific error. |
| See also | |
|---|---|
decodeFromSavedState |