Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin annotated services don't support value classes with suspended methods #5294

Closed
jrhee17 opened this issue Nov 10, 2023 · 0 comments · Fixed by #5449
Closed

Kotlin annotated services don't support value classes with suspended methods #5294

jrhee17 opened this issue Nov 10, 2023 · 0 comments · Fixed by #5449
Labels
Milestone

Comments

@jrhee17
Copy link
Contributor

jrhee17 commented Nov 10, 2023

Note that it seems like this issue is fixed in the newer versions of kotlin (1.9.20), but we should check this works once we upgrade.

kotlin side: https://youtrack.jetbrains.com/issue/KT-58887/Reflection-IllegalArgumentException-argument-type-mismatch-when-using-reflection-to-invoke-a-value-class-returning-function-that
spring side: spring-projects/spring-framework#27345
discord ref: https://discord.com/channels/1087271586832318494/1172096171318181918/1172417425933860904

Reproducer:

@Test
    fun fooTest() {
        runTest {
            val res = server.blockingWebClient({cb ->
                cb.addHeader(HttpHeaderNames.CONTENT_TYPE, "application/json")
                    .responseTimeoutMillis(0)
                    .writeTimeoutMillis(0)
            })
                .post("/hello/foo", """
                    {
                        "hello": "world!",
                        "hi": 123
                    }
                """.trimIndent())
            logger.info("res: ${res}")
        }
    }

    companion object {
        private val logger = LoggerFactory.getLogger(MyTest::class.java)

        @RegisterExtension
        val server: ServerExtension = object : ServerExtension() {
            override fun configure(sb: ServerBuilder) {
                sb.idleTimeoutMillis(0)
                    .requestTimeoutMillis(0)
                sb.annotatedService()
                    .pathPrefix("/hello")
                    .build(MyAnnotatedService())
                sb.errorHandler(object: ServerErrorHandler {
                    override fun onServiceException(
                        ctx: ServiceRequestContext,
                        cause: Throwable
                    ): HttpResponse? {
                        logger.warn("onServiceException: ", cause)
                        return null
                    }
                })
            }
        }

        data class Inner(val hello: String, val hi: Int)

        @JvmInline
        value class TestClass(val inner: Inner)

        private class MyAnnotatedService {
            @Post("/foo")
            @ProducesJson
            suspend fun foo(testClass: TestClass): TestClass {
                println("testClass :${testClass}")
                return TestClass(Inner("world", 456))
            }
        }
    }
@jrhee17 jrhee17 added the defect label Nov 10, 2023
@jrhee17 jrhee17 added this to the 1.27.0 milestone Nov 10, 2023
@minwoox minwoox modified the milestones: 1.27.0, 1.28.0 Jan 26, 2024
ikhoon added a commit to ikhoon/armeria that referenced this issue Feb 7, 2024
@jrhee17 jrhee17 closed this as completed in d71803d Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants