Kotlin Seralization-Custom seralizer to decode old enum data to new object data

Viewed 15

I'm trying to deserialize a JSON file to a Kotlin data class I cannot control using kotlinx.serialization.

The class looks likes:

data class Target
(
  private val a: String?=null,
  private val b: B? =null
)

data class B (val bb: Enum ?= null)

The old data json in my local such as: `{"a": "123", "b":{"bb": "Shape"}}`

And I try to change the structure of B looks like:

data class B(val bb: C ?= null)

data class C(val cc: String, val dd:String)
How can I make sure the old data is deserialized correctly into my new model row via custom serialization?
0 Answers
Related