Hello. To parse JSON with kotlinx.serialization I use data classes. How this structure could be improved?
@Serializable
data class Parent(
@SerialName("Parent")
val someClass: SomeClass
)
@Serializable
data class SomeClass(
@SerialName("SpaceShip")
val ship: String,
@SerialName("Mark")
val mark: Int
)
Main code:
fun getSomeClass(inputStream: InputStream): SomeClass {
val json = Json(JsonConfiguration.Stable)
val jsonString = Scanner(inputStream).useDelimiter("\\A").next()
val parent = json.parse(Parent.serializer(), jsonString)
return parent.someClass
}
Is it possible to make a nested data class or to use some kind of Any type and act like in Javascript? There can be a lot of unnecessary data in JSON responce and some of important are within 4+ level from top. Is there a kind of fast adapter mechanism persists?