Slide 15
Slide 15 text
Make the objects serializable with kotlinx.serialization
4. Serialize an object with formatter
@Serializable
data class SampleScreenState(
val familyName: String,
val givenName: String,
val age: Int
)
val originalState = SampleScreenState("foo", "bar", 30)
val json = Json(JsonConfiguration.Stable)
// {"familyName":"foo","givenName":"bar","age":30}
val serialized = json.stringify(originalState)
val restoredState =
json.parse(SampleScreenState::class.serializer(), serialized)
15
potatotips #67