Skip to content

Commit

Permalink
Make Saveable serializable
Browse files Browse the repository at this point in the history
It was marked with `@Contextual`, but a serializer was never being passed in, therefore it crashes as it can't find a serializer. The class is trivial to serialize, so we can just annotate it with `@Serializable` for a serialization adapter to be generated for us.
  • Loading branch information
veyndan committed Sep 28, 2023
1 parent 8a90744 commit a48e231
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package app.cash.redwood.treehouse
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import kotlin.jvm.JvmInline
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
Expand All @@ -29,7 +28,7 @@ import kotlinx.serialization.json.intOrNull

@Serializable
public class StateSnapshot(
public val content: Map<String, List<@Contextual Saveable>>,
public val content: Map<String, List<Saveable>>,
) {
public fun toValuesMap(): Map<String, List<Any?>> {
return content.mapValues { entry ->
Expand Down Expand Up @@ -89,6 +88,7 @@ private fun JsonElement?.fromJsonElement(): Any {
}
}

@Serializable
public data class Saveable(
val isMutableState: Boolean,
val value: JsonElement,
Expand Down

0 comments on commit a48e231

Please sign in to comment.