Open XhstormR opened 2 years ago
When I make a successful call to make an http request, but it fails when converting the http call result json into an object. When I remove the suspend
modifier in the method, try again and it will be successful.
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:761) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:748) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:309) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
at io.github.xhstormr.masker.ApplicationKt.main(Application.kt:54) ~[main/:na]
Caused by: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class io.github.xhstormr.masker.model.response.RestResponse (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; io.github.xhstormr.masker.model.response.RestResponse is in unnamed module of loader 'app')
at io.github.xhstormr.masker.web.api.masker.MaskerApi.maskSync(MaskerApi.kt:32) ~[main/:na]
at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:710) ~[na:na]
at feign.DefaultMethodHandler.invoke(DefaultMethodHandler.java:141) ~[feign-core-11.7.jar:na]
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-11.7.jar:na]
at com.sun.proxy.$Proxy116.maskSync(Unknown Source) ~[na:na]
at io.github.xhstormr.masker.Application.init$lambda-0(Application.kt:45) ~[main/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:758) ~[spring-boot-2.6.2.jar:2.6.2]
... 5 common frames omitted
Hello, @XhstormR. We have never introduced kotlin support in Spring Cloud OpenFeign, so there might be many Kotlin constructs that will not work. Putting the issue into ice-box as currently we are not working on Kotlin support.
It looks like OpenFeign recently merged in support for Kotlin suspend functions https://github.com/OpenFeign/feign/pull/1706. When that PR is released and spring-cloud-openfeign can update, will suspend functions 'just work'?
We'll review it. If it requires only minimal changes, we'll possibly implement support here also. However, if it's more involved, then Kotlin support is currently not a priority. However, we would review a PR if it's submitted.
OpenFeign 12.0 was released with support for Kotlin coroutines. By looking at the test case CoroutineFeignTest
, we simply need to build the Client using CoroutineFeign
to get invocation support for the Kotlin coroutine.
Since the Feign
class and the CoroutineFeign
class have nothing in common, it is not trivial to add this support to spring-cloud-openfeign
. I think it is a better fit for https://github.com/spring-projects-experimental/spring-cloud-openfeign-async if that ever gets written.
I have an API interface where the methods are kotlin suspend methods:
But when I run the program, the program throws an exception:
This
kotlin.coroutines.Continuation
parameter is generated by the kotlin compiler at compile time, so I can't modify this parameter, how can I tell FeignClient to ignore this Continuation parameter?