I have the following user table object & entity class:
object UserTable : IntIdTable() {
val name = varchar("name", 256)
}
class User(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<User>(UserTable)
val name by UserTable.name
}
Is there a way to use Gson (or some other library) to parse JSON
into a User
instance, and then insert it? From what I can tell,
it seems like I'll have to create an intermediate UserData
data class and then manually copy the fields over.
data class UserData {
var id: Int?
var name: String?
}
fun main() {
val data = Gson().fromJson<UserData>("...", UserData::class.java)
val user = User.new {
name = data.name
}
}
It's not that bad in this contrived example, but I'm wondering if there's a dry'er approach.