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

@HttpExchange interface does not resolve return type correctly while using with suspending methods #30266

Closed
xnart opened this issue Apr 2, 2023 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: bug A general bug
Milestone

Comments

@xnart
Copy link

xnart commented Apr 2, 2023

Affects: 6.0.7

@HttpExchange annotated methods works as expected for simple return types, but not for generic types. For example a function expected to return List, but HttpServiceProxy resolves it as String.

interface SuspendingService {

  @GetExchange
  suspend fun body(): List<String>
}

Here is a test case :

class HttpServiceMethodKotlinTests {

  private val EXPECTED_BODY_TYPE: ParameterizedTypeReference<*> = object : ParameterizedTypeReference<List<String>>() {}

  private val client = TestHttpClientAdapter()
  private val proxyFactory = HttpServiceProxyFactory.builder(client).build()

  @Test
  fun suspendingService(): Unit = runBlocking {
    val service = proxyFactory.createClient(SuspendingService::class.java)

    service.body()
    getVerifyClientInvocation("requestToBody", EXPECTED_BODY_TYPE)
  }

  private fun getVerifyClientInvocation(methodName: String, expectedBodyType: ParameterizedTypeReference<*>) {
    assertThat(client.invokedMethodName).isEqualTo(methodName)
    assertThat(client.bodyType).isEqualTo(expectedBodyType)
  }


  private interface SuspendingService {
    @GetExchange
    suspend fun body(): List<String>
  }
}

Result:

expected: ParameterizedTypeReference<java.util.List<? extends java.lang.String>>
 but was: ParameterizedTypeReference<class java.lang.String>

When you change function signature as fun body(): Mono<List<String>> it returns ParameterizedTypeReference<java.util.List<java.lang.String>> as expected.

As far as i see, Only "suspending methods" affected by it. Flows works as expected.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 2, 2023
@sdeleuze sdeleuze self-assigned this Apr 3, 2023
@sdeleuze sdeleuze added theme: kotlin An issue related to Kotlin support and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 3, 2023
@sdeleuze sdeleuze added this to the 6.0.8 milestone Apr 3, 2023
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants