micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

@Client dont suppot suspend #3058

Closed tmtbe closed 4 years ago

tmtbe commented 4 years ago

Thanks for reporting an issue for Micronaut, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

when i used suspend fun in Client,they don't work.

when i used Result Object

@Controller class HelloController : HelloOperations { override suspend fun hello(@PathVariable name: String): Result { return Result ("hello $name") } } interface HelloOperations { @Get("/{name}") suspend fun hello(@PathVariable name: String): Result } @Client("/") interface HelloClient : HelloOperations data class Result( val msg: String )

trace:

class java.util.LinkedHashMap cannot be cast to class hello.world.kotlin.Result (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; hello.world.kotlin.Result is in unnamed module of loader 'app') java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class hello.world.kotlin.Result (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; hello.world.kotlin.Result is in unnamed module of loader 'app') at hello.world.kotlin.HelloControllerTest$1.invokeSuspend(HelloControllerTest.kt:18)

when i used String

@Controller class HelloController : HelloOperations { override suspend fun hello(@PathVariable name: String): String { return "hello $name" } } interface HelloOperations { @Get("/{name}") suspend fun hello(@PathVariable name: String): String } @Client("/") interface HelloClient : HelloOperations

trace:

12:51:06.378 [pool-2-thread-1 @coroutine#4] ERROR i.m.r.intercept.RecoveryInterceptor - Type [hello.world.kotlin.HelloClient$Intercepted] executed with error: Error decoding HTTP response body: Error decoding stream for type [class java.lang.Object]: Unrecognized token 'hello': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (byte[])"hello joy"; line: 1, column: 7] io.micronaut.http.client.exceptions.HttpClientResponseException: Error decoding HTTP response body: Error decoding stream for type [class java.lang.Object]: Unrecognized token 'hello': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (byte[])"hello joy"; line: 1, column: 7] at io.micronaut.http.client.netty.DefaultHttpClient$12.channelRead0(DefaultHttpClient.java:2059) at io.micronaut.http.client.netty.DefaultHttpClient$12.channelRead0(DefaultHttpClient.java:1932) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)

Steps to Reproduce

Expected Behaviour

Tell us what should happen

Actual Behaviour

Tell us what happens instead

Environment Information

Example Application

interface HelloOperations { @Get("/{name}") suspend fun hello(@PathVariable name: String): Result }

data class Result( val msg: String )

@MicronautTest class HelloControllerTest : StringSpec() { @Inject lateinit var embeddedServer: EmbeddedServer

@Inject
lateinit var helloClient: HelloClient

init {
    "test hello controller" {
        val hello = helloClient.hello("joy")
        hello.msg shouldBe "hello joy"
    }
}

}

bjuretic commented 4 years ago

Confirmed, on RC1.