Support Kotlin value class properties in SpEL

This commit adds support for inlined Kotlin value
class properties in SpEL by leveraging Kotlin
reflection instead of Java reflection broken
by the mangled method name.

Closes gh-30468
This commit is contained in:
Sébastien Deleuze
2023-08-11 16:52:44 +02:00
parent 566621f7e3
commit 1e73439955
3 changed files with 60 additions and 1 deletions

View File

@@ -55,6 +55,20 @@ class SpelReproKotlinTests {
assertThat(expr.getValue(context, Boolean::class.java)).isFalse()
}
@Test
fun `gh-30468 Unmangle Kotlin inlined class getter`() {
context.setVariable("something", Something(UUID(123), "name"))
val expr = parser.parseExpression("#something.id")
assertThat(expr.getValue(context, Int::class.java)).isEqualTo(123)
}
@Test
fun `gh-30468 Unmangle Kotlin inlined class setter`() {
context.setVariable("something", Something(UUID(123), "name"))
val expr = parser.parseExpression("#something.id = 456")
assertThat(expr.getValue(context, Int::class.java)).isEqualTo(456)
}
@Suppress("UNUSED_PARAMETER")
class Config {
@@ -71,4 +85,11 @@ class SpelReproKotlinTests {
}
}
@JvmInline value class UUID(val value: Int)
data class Something(
var id: UUID,
var name: String,
)
}