Hi, is there any library or a way to use Kotlinx Serialization with a serializer that converts the MutableStates to their values (same with lists/maps) ?
d
Dominaezzz
12/17/2021, 2:46 PM
Probably. Can you provide an example class you want to serialize?
a
Ayfri
12/17/2021, 2:52 PM
Copy code
interface Template {
@Composable
fun Content()
}
abstract class VanillaCraft : Template
class ItemTemplate : VanillaTemplate() {
val id = mutableStateOf("")
val tag = mutableStateOf("")
override fun Content() { /* ... */ }
}
d
Dominaezzz
12/17/2021, 2:53 PM
Yes you can annonate
ItemTemplate
with
@Serializable
and annotate
id
and
tag
with a small custom serializer to do the wrap/unwrap for you.
a
Ayfri
12/17/2021, 3:05 PM
But I have a small problem, I have this :
Copy code
@Serializable
abstract class CookingRecipeSingle(
type: RecipeType,
) : RecipeTemplate() {
@SerialName("cookingtime")
val cookingTime = mutableStateOf(0)
val experience = mutableStateOf(0.0)
val group = mutableStateOf("")
val ingredient = mutableStateOf(ItemTemplate())
val result = mutableStateOf("")
init {
this.type.value = type
}
override fun Content() { /* ... */ }
}
This class is used by multiple other classes
RecipeType is an enum
Exemple :