Add support for @RequestMapping on Kotlin property accessors

This commit refines InvocableHandlerMethod (both Servlet and
Reactive variants) in order to support annotated property
accessors as they translate into regular Java methods, instead
of throwing a NullPointerException.

Closes gh-31856
This commit is contained in:
Sébastien Deleuze
2023-12-19 12:24:13 +01:00
parent 917978cbc2
commit 12f01f9b5f
4 changed files with 40 additions and 6 deletions

View File

@@ -98,6 +98,12 @@ class InvocableHandlerMethodKotlinTests {
Assertions.assertThat(value).isEqualTo(3.1)
}
@Test
fun propertyAccessor() {
val value = getInvocable(PropertyAccessorHandler::class.java).invokeForRequest(request, null)
Assertions.assertThat(value).isEqualTo("foo")
}
private fun getInvocable(clazz: Class<*>, vararg argTypes: Class<*>): InvocableHandlerMethod {
val method = ResolvableMethod.on(clazz).argTypes(*argTypes).resolveMethod()
val handlerMethod = InvocableHandlerMethod(clazz.constructors.first().newInstance(), method)
@@ -138,6 +144,12 @@ class InvocableHandlerMethodKotlinTests {
limit.value
}
private class PropertyAccessorHandler {
val prop: String
get() = "foo"
}
@JvmInline
value class LongValueClass(val value: Long)