Skip to content

Commit 3e8c9c4

Browse files
committed
Make the type converters more Kotlin-ish
1 parent 0b39d41 commit 3e8c9c4

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/test/kotlin/examples/kotlin/spring/canonical/DomainAndConverters.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ import java.util.*
1919

2020
data class LastName(val name: String)
2121

22-
fun lastNameConverter(source: LastName?) = source?.name
22+
val lastNameConverter: (LastName?) -> String? = { it?.name }
2323

24-
fun booleanToStringConverter(source: Boolean?): String {
25-
fun Boolean.asString() = if(this) "Yes" else "No"
26-
return source?.asString()?:"No"
27-
}
24+
val booleanToStringConverter: (Boolean?) -> String = { it?.let { if (it) "Yes" else "No" } ?: "No" }
2825

2926
data class PersonRecord(
3027
var id: Int? = null,
@@ -59,7 +56,7 @@ data class AddressRecord(
5956
var state: String? = null
6057
)
6158

62-
data class GeneratedAlwaysRecord (
59+
data class GeneratedAlwaysRecord(
6360
var id: Int? = null,
6461
var firstName: String? = null,
6562
var lastName: String? = null,

src/test/kotlin/examples/kotlin/spring/canonical/PersonDynamicSqlSupport.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ object PersonDynamicSqlSupport {
2424
val id = column<Int>("id", JDBCType.INTEGER)
2525
val firstName = column<String>("first_name", JDBCType.VARCHAR)
2626
val lastName = column<LastName>("last_name", JDBCType.VARCHAR)
27-
.withParameterTypeConverter(::lastNameConverter)
27+
.withParameterTypeConverter(lastNameConverter)
2828
val birthDate = column<Date>("birth_date", JDBCType.DATE)
2929
val employed = column<Boolean>("employed", JDBCType.VARCHAR)
30-
.withParameterTypeConverter(::booleanToStringConverter)
30+
.withParameterTypeConverter(booleanToStringConverter)
3131
val occupation = column<String>("occupation", JDBCType.VARCHAR)
3232
val addressId = column<Int>("address_id", JDBCType.INTEGER)
3333
}

0 commit comments

Comments
 (0)