简体   繁体   中英

Using enums as query params in Resteasy Reactive / Quarkus

Im trying to use a Kotlin enum as a query parameter in my rest controller but without any success.

My affected code looks like this:

enum class FieldExclusion {
    AUTHOR_FIELD,
    TIME_FIELD
}

...

 @GET
    fun get(
        @RestPath id: UUID,
        @RestQuery excludedFields: List<FieldExclusion>?,
        @Context httpRequest: HttpServerRequest
    ): Uni<Response> {

...

After including this code, mvn can't build my project and throws this error:

2021-04-12 20:49:30,553 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor#setupEndpoints threw an exception: java.lang.RuntimeException: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:238)
    at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:402)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:920)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    at java.base/java.lang.Thread.run(Thread.java:832)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:526)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:285)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:209)
    ... 11 more
Caused by: java.lang.RuntimeException: Unknown parameter type ? extends com.kzman.zukus.common.request.model.FieldExclusion
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.toClassName(EndpointIndexer.java:701)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractParameterInfo(EndpointIndexer.java:889)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:407)
    ... 13 more

    at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:396)
    at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:269)
    at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:66)
    at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:79)
    at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:378)
    at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:56)
    at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:127)
    at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
    at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:144)
    at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:63)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor#setupEndpoints threw an exception: java.lang.RuntimeException: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:238)
    at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:402)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:920)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    at java.base/java.lang.Thread.run(Thread.java:832)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:526)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:285)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:209)
    ... 11 more
Caused by: java.lang.RuntimeException: Unknown parameter type ? extends com.kzman.zukus.common.request.model.FieldExclusion
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.toClassName(EndpointIndexer.java:701)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractParameterInfo(EndpointIndexer.java:889)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:407)
    ... 13 more

    at io.quarkus.builder.Execution.run(Execution.java:116)
    at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
    at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:153)
    at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:394)
    ... 9 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:238)
    at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:402)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:920)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    at java.base/java.lang.Thread.run(Thread.java:832)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.RuntimeException: Failed to process method com.kzman.zukus.user.controller.UserController#io.smallrye.mutiny.Uni<javax.ws.rs.core.Response> get(java.util.UUID id, java.util.List<? extends com.kzman.zukus.common.request.model.FieldExclusion> excludedFields, io.vertx.core.http.HttpServerRequest httpRequest)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:526)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:285)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:209)
    ... 11 more
Caused by: java.lang.RuntimeException: Unknown parameter type ? extends com.kzman.zukus.common.request.model.FieldExclusion
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.toClassName(EndpointIndexer.java:701)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractParameterInfo(EndpointIndexer.java:889)
    at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:407)
    ... 13 more

2021-04-12 20:49:30,553 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start hot replacement endpoint to recover from previous Quarkus startup failure

The founded documentation says that enum classes are also supported.

Types that have a static method named valueOf or fromString with a single String argument that return an instance of the type. If both methods are present then valueOf will be used unless the type is an enum in which case fromString will be used.

Since in Kotlin I can't add static functions (companion funs) to enums, is there any way to solve it instead of using plain Strings and convert them manually? I also tried to add a value to the primary constructor but that failed as well.

enum class FieldExclusion(val value : String) {
    AUTHOR_FIELD("AUTHOR_FIELD"),
    TIME_FIELD("TIME_FIELD")
}

Thank you very much for your help!

I don't think this is problem with kotlin. Kotlin enums have static valueOf pregenerated so that's not a problem.

Also you can add static methods for jvm using kotlin like this:

companion object {
    @JvmStatic
    fun fromString(text: String): A {
        //TODO: do your thing
    }
}

I don't see any part of that exception, that would indicate, that it's problem of this enum. Am I missing something there?

This sounds like a bug.

Please open an issue on the Quarkus GitHub issue tracker with a project we can use to reproduce the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM