Skip to content

Commit

Permalink
Allow empty @BeanParam class with non-empty super class
Browse files Browse the repository at this point in the history
Fixes: #22941
  • Loading branch information
geoand committed Jan 18, 2022
1 parent 34ca62f commit 3af2384
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
}

0 comments on commit 3af2384

Please sign in to comment.