有没有一种方法和/或库可以像在 Scala Json.Spray 中一样从 Json 自动创建 Kotlin Data 类?
像这样的东西:
data class User(id: Int, name: String)
class DataClassFactory(val json: String) {
fun getUser(): User {
//some reflection
return User(10, "Kirill")
}
}
fun main(args: Array<String>): Unit {
val json = "{id: 10, name: Kirill}"
val usr = DataClassFactory(json).getUser()
println(usr)
}