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

[rest-client] @RestForm does not work with a Map #43784

Closed
PierreBtz opened this issue Oct 9, 2024 · 4 comments · Fixed by #43855
Closed

[rest-client] @RestForm does not work with a Map #43784

PierreBtz opened this issue Oct 9, 2024 · 4 comments · Fixed by #43855
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@PierreBtz
Copy link

Describe the bug

Using @RestForm with a Map<String,String> fails with the following message: java.lang.IllegalStateException: Form element 'org.acme.rest.client.ExtensionsService.postFilter' could not be converted to 'String' for REST Client interface 'org.acme.rest.client.ExtensionsService'. A proper implementation of 'jakarta.ws.rs.ext.ParamConverter' needs to be returned by a 'jakarta.ws.rs.ext.ParamConverterProvider' that is registered with the client via the @RegisterProvider annotation on the REST Client interface.

Expected behavior

It should be possible to annotate a Map<String, String> (or Map<T,T> with T following the contract of the FormParam javadoc) with @RestForm.

Note: I'm aware that Map itself doesn't follow the contract but according to the rest client quickstart, this should be supported.

Actual behavior

When writing something like:

   @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    Set<Extension> postFilter(@RestForm Map<String, String> filter);

I observe:

java.lang.IllegalStateException: Form element 'org.acme.rest.client.ExtensionsService.postFilter' could not be converted to 'String' for REST Client interface 'org.acme.rest.client.ExtensionsService'. A proper implementation of 'jakarta.ws.rs.ext.ParamConverter' needs to be returned by a 'jakarta.ws.rs.ext.ParamConverterProvider' that is registered with the client via the @RegisterProvider annotation on the REST Client interface.
	at org.acme.rest.client.ExtensionsService$$QuarkusRestClientInterface.postFilter(Unknown Source)
	at org.acme.rest.client.ExtensionsService$$CDIWrapper.postFilter(Unknown Source)
	at org.acme.rest.client.ExtensionsService$$CDIWrapper_ClientProxy.postFilter(Unknown Source)
	at org.acme.rest.client.ExtensionsResource.postFilter(ExtensionsResource.java:44)
	at org.acme.rest.client.ExtensionsResource$quarkusrestinvoker$postFilter_f150e3b45248e706abefa90223a2969c9c2ba0d0.invoke(Unknown Source)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:635)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1583)

How to Reproduce?

    @POST
    @Path("/test")
    public Set<Extension> postFilter() {
        return extensionsService.postFilter(Map.of("hello", "world"));
    }

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    Set<Extension> postFilter(@RestForm Map<String, String> filter);
  • Start the application: mvn quarkus:dev

  • Trigger the problematic code: curl -X POST http://localhost:8080/extension/test

Output of uname -a or ver

Darwin *** 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:39 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.4" 2024-07-16 LTS OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)

Quarkus version or git rev

3.15.1

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /Users/***/.asdf/installs/maven/3.9.6 Java version: 21.0.4, vendor: Eclipse Adoptium, runtime: /Users/pierrebeitz/.asdf/installs/java/temurin-21.0.4+7.0.LTS Default locale: en_FR, platform encoding: UTF-8 OS name: "mac os x", version: "14.7", arch: "aarch64", family: "mac"

Additional information

No response

@PierreBtz PierreBtz added the kind/bug Something isn't working label Oct 9, 2024
Copy link

quarkus-bot bot commented Oct 9, 2024

/cc @cescoffier (rest-client), @geoand (rest-client)

@PierreBtz
Copy link
Author

Attaching a patch to simplify the reproduction.

gh-43784.patch

geoand added a commit to geoand/quarkus that referenced this issue Oct 14, 2024
geoand added a commit to geoand/quarkus that referenced this issue Oct 14, 2024
geoand added a commit that referenced this issue Oct 14, 2024
Properly handle Map of form params in REST Client
@quarkus-bot quarkus-bot bot added this to the 3.16 - main milestone Oct 14, 2024
@PierreBtz
Copy link
Author

Thanks for the fast fix!

@geoand
Copy link
Contributor

geoand commented Oct 14, 2024

👌

@gsmet gsmet modified the milestones: 3.16.0.CR1, 3.15.2 Oct 18, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 21, 2024
bschuhmann pushed a commit to bschuhmann/quarkus that referenced this issue Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants