Fixed
Status Update
Comments
mg...@google.com <mg...@google.com> #2
Related to
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
Author: Marcello Galhardo <
Link:
Add MutableStateFlowSerializer
for serializing MutableState
Expand for full commit details
Add `MutableStateFlowSerializer` for serializing `MutableState`
- Introduced an inline `MutableStateFlowSerializer` function to infer and retrieve the appropriate `KSerializer` for `MutableStateFlow` of a serializable type.
- Added an overload of `MutableStateFlowSerializer` that accepts an explicit `KSerializer` for the wrapped type, allowing for customizing the `KSerializer`.
- Implemented `MutableStateFlowSerializerImpl`, a private class that handles the serialization and deserialization logic for `MutableStateFlow`, delegating inner value processing to the provided `KSerializer`.
- Only `KSerializer<MutableStateFlow<T>>` is exposed; the `MutableStateFlowSerializerImpl` remains private.
RelNote: "Add `MutableStateFlowSerializer` for serializing `kotlinx.coroutines.flow.MutableStateFlow`."
Test: MutableStateFlowSerializerTest.kt
Fixes: 378895070
Change-Id: I6a8925772d2f124d2db4a83bff0062c1db0eb0fb
Files:
- M
savedstate/savedstate/api/current.txt
- M
savedstate/savedstate/api/restricted_current.txt
- M
savedstate/savedstate/bcv/native/current.txt
- M
savedstate/savedstate/build.gradle
- A
savedstate/savedstate/src/commonMain/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer.kt
- A
savedstate/savedstate/src/commonTest/kotlin/androidx/savedstate/serialization/MutableStateFlowSerializerTest.kt
Hash: 3f45907910984f32745d62d9846e7083a3c75e4a
Date: Mon Jan 20 12:32:07 2025
na...@google.com <na...@google.com> #4
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.savedstate:savedstate:1.3.0-alpha07
androidx.savedstate:savedstate-android:1.3.0-alpha07
androidx.savedstate:savedstate-desktop:1.3.0-alpha07
androidx.savedstate:savedstate-iosarm64:1.3.0-alpha07
androidx.savedstate:savedstate-iossimulatorarm64:1.3.0-alpha07
androidx.savedstate:savedstate-iosx64:1.3.0-alpha07
androidx.savedstate:savedstate-linuxarm64:1.3.0-alpha07
androidx.savedstate:savedstate-linuxx64:1.3.0-alpha07
androidx.savedstate:savedstate-macosarm64:1.3.0-alpha07
androidx.savedstate:savedstate-macosx64:1.3.0-alpha07
Description
saveable
has built-in support for Coroutines'MutableStateFlow
, supporting the following use case:It does this by providing an overloaded function that handles
MutableStateFlow.value
and serializes it when needed.To help people migrate from
saveable
tosaved
, we want to supportMutableStateFlow
in our KotlinX serialization support.While working on getMutableStateFlow CL, I experimented with this idea and created a naive
KSerializer
implementation to handleMutableStateFlow
.Here’s what it could look like:
For serialization, we would use
(value as MutableStateFlow<T>).value
+valueSerializer
to serialize the content. Deserialization works in the opposite direction.Here’s a usage example:
However, calling this without the serializer would cause an exception.
Our variant should work like
saveable
: ifT
(the generic type insaved
) is serializable, it should work without needing the serializer.The goal is to find the best way to support
MutableStateFlow
insaved
.Related to b/378895074 .