I’ve got some compiler warnings of `Kotlin: Expect...
# spring
m
I’ve got some compiler warnings of
Kotlin: Expected type does not accept nulls in Java, but the value may be null in Kotlin
around a
MapSqlParameterSource("key", null)
- but the value can be null, as far as I can tell.
n
you might be able to tell but it seems the compiler cannot perhaps you might have missed
@NotNull
annotations?
t
I ran into this same thing. It appears that
MapSqlParameterSource
doesn't have its
@Nullable
annotation set properly. But if you think about it, the reason that class exists is because there's no elegant way to express Maps in Java. But in Kotlin we have
mapOf("key" to null)
, which works as an argument to
NamedParameterJdbcTemplate
(assuming that's where you are using this).
m
Ahh, so I could build the map first, then construct the
MapSqlParameterSource
from it, rather than using the
addValue
on the MSPS. That makes sense!
(I’m actually using Spring Batch, not the template directly, so it I have to provide a
setItemSqlParameterSourceProvider
or a
setItemPreparedStatementSetter
. 📯