From 3af2384ae280146b2b08810748ee7991406909e5 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 18 Jan 2022 16:27:50 +0200 Subject: [PATCH] Allow empty @BeanParam class with non-empty super class Fixes: #22941 --- .../processor/ServerEndpointIndexer.java | 4 +- .../simple/BeanParamEmptySubclassTest.java | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/BeanParamEmptySubclassTest.java diff --git a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java index 48d9a3e77a42f..6d44b35600c0c 100644 --- a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java +++ b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java @@ -167,7 +167,7 @@ protected boolean handleBeanParam(ClassInfo actualEndpointInfo, Type paramType, InjectableBean injectableBean = scanInjectableBean(beanParamClassInfo, actualEndpointInfo, existingConverters, additionalReaders, injectableBeans, hasRuntimeConverters); - if (injectableBean.getFieldExtractorsCount() == 0) { + if ((injectableBean.getFieldExtractorsCount() == 0) && !injectableBean.isInjectionRequired()) { throw new DeploymentException(String.format("No annotations found on fields at '%s'. " + "Annotations like `@QueryParam` should be used in fields, not in methods.", beanParamClassInfo.name())); @@ -288,7 +288,7 @@ protected InjectableBean scanInjectableBean(ClassInfo currentClassInfo, ClassInf currentInjectableBean.setFieldExtractorsCount(fieldExtractors.size()); - if (!fieldExtractors.isEmpty() && fieldInjectionHandler != null) { + if ((fieldInjectionHandler != null) && (!fieldExtractors.isEmpty() || superTypeIsInjectable)) { fieldInjectionHandler.handleFieldInjection(currentTypeName, fieldExtractors, superTypeIsInjectable); } currentInjectableBean.setInjectionRequired(!fieldExtractors.isEmpty() || superTypeIsInjectable); diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/BeanParamEmptySubclassTest.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/BeanParamEmptySubclassTest.java new file mode 100644 index 0000000000000..3d467742ef913 --- /dev/null +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/BeanParamEmptySubclassTest.java @@ -0,0 +1,58 @@ +package org.jboss.resteasy.reactive.server.vertx.test.simple; + +import io.restassured.RestAssured; +import javax.ws.rs.BeanParam; +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.hamcrest.Matchers; +import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class BeanParamEmptySubclassTest { + + @RegisterExtension + static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(TestResource.class, BaseParams.class, Params.class)); + + @Test + public void test() { + RestAssured.given().formParam("param1", "foo").post("/bean?param2=bar") + .then().statusCode(200).body(Matchers.equalTo("foo/bar")); + } + + @Path("bean") + public static class TestResource { + + @POST + @Produces(MediaType.TEXT_PLAIN) + public String hello(final @BeanParam BaseParams params) { + return params.getParam1() + "/" + params.getParam2(); + } + } + + public static class BaseParams { + @FormParam("param1") + private String param1; + + @QueryParam("param2") + private String param2; + + public String getParam1() { + return param1; + } + + public String getParam2() { + return param2; + } + } + + public static class Params extends BaseParams { + + } +}