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

Allow empty @BeanParam class with non-empty super class #22972

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

}
}