Hi guys, I am trying to use R2DBC but am getting a...
# announcements
v
Hi guys, I am trying to use R2DBC but am getting a “java.lang.IllegalArgumentException: Cannot decode value of type boolean” when trying to serialize the results in a RowMapper
Copy code
private val myRowMapper = BiFunction<Row, RowMetadata, Person> { row, _ ->
            Person(
                row["Id", Integer::class.java]!!.toInt(), row["NAME", String::class.java]!!,
                row["StudentId", Integer::class.java]!!.toInt(),
                row["GroupId", Integer::class.java]?.toInt(), row["startDate", Instant::class.java]!!,
                row["endDate", Instant::class.java], row["authId", Integer::class.java]!!.toInt(),
                row["statusId", Integer::class.java]?.toInt(),
                row["IS_TEST", Boolean::class.java]!!,
                row["DELETED", Boolean::class.java]
            )
        }

databaseClient.execute(myQuery).bind("Id" to "12345").map(myRowMapper).flow().toList()

data class Person(
val id: Int,
val name: String,
val studentId: Int,
val groupId: Int?,
startDate: Instant,
endDate: Instant?,
authId: Int,
statusId: Int,
isTest: Boolean,
deleted: Boolean?)
Am I doing this correctly. It seems like I have to do an awful lot of conversions just to get a simple data type like Int / Boolean
m
What database are you using?
v
postgresql
m
R2DBC is a very low level API, so don't expect the code to look nice 😛
v
fair point, at the moment would be fine if I was just serializing correctly ugly and all, is there anything special about Kotlin types / nullable values?
m
I think most databases doesn't have a standard boolean type, so R2DBC might not support it directly. Although I'm not sure.
Nothing special about the Kotlin types. A Kotlin Boolean maps directly to a Java boolean.
d
My god that was an ugly API. JDBI ❤️
m
Well, the point of that API is to create frameworks on top of it. Not to use it directly from your application code. 😛