toObjects
Maps the ResultSet to a List of objects that are created using the given factory lambda.
Example of usage with kotlinx-serialization:
@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)
val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}
Content copied to clipboard
Return
Parameters
factory
lambda used for creating an object instance
Maps the ResultSet to a List of objects that are created using the given factory lambda.
Example of usage:
class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}
val users: List<User> = query.execute().toObjects(::User)
Content copied to clipboard
Using Kotlin Map delegation for creating such instances is a great shorthand.
Return
Parameters
factory
lambda used for creating an object instance