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 #34836

Closed
xnart opened this issue Apr 2, 2023 · 1 comment
Labels
for: external-project For an external project and not something we can fix

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.

@xnart
Copy link
Author

xnart commented Apr 2, 2023

Sorry, opened it on wrong repository. Copied it to spring-projects/spring-framework#30266

@xnart xnart closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2023
@scottfrederick scottfrederick added the for: external-project For an external project and not something we can fix label Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

2 participants