Serialization data migration

I’m trying to learn the recommended way to do data migration with kotlinx serialization.

Let’s say for example I have data that was previously saved as JSON using:

@Serializable
data class Foo(
    val a: String,
    val b: Int,
    val c: Float,
    val d: String
)

And I want to read old data and migrate it to a new format:

@Serializable
data class Foo(
    val bar: Bar,
    val d: String
)

@Serializable
data class Bar(
    val a: String,
    val b: Int,
    val c: Float
)

What’s the best way to go about this?

There are better tools available for storing versioned data with version migration. I would recommend to use one of those and use json serialization only for the transfer of data.

1 Like

Any that are multi-platform? Do you have a favorite?