Skip to content

Commit

Permalink
Register enclosing class for reflection when used as JAX-RS return type
Browse files Browse the repository at this point in the history
This is needed when a JAX-RS resource returns a parameterized type that
is meant to be an enclosing class

Fixes: quarkusio#3538
  • Loading branch information
geoand authored and Dufgui committed Aug 26, 2019
1 parent 518c6fb commit f171059
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
@@ -1,6 +1,7 @@
package io.quarkus.deployment.steps;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class ReflectiveHierarchyStep {

private static final Logger log = Logger.getLogger(ReflectiveHierarchyStep.class);

private static final Set<String> IGNORED_PARAMETERIZED_TYPE_PACKAGE_NAMES = new HashSet<>(
Arrays.asList("java.util", "io.reactivex"));

@Inject
List<ReflectiveHierarchyBuildItem> hierarchy;

Expand Down Expand Up @@ -83,7 +87,9 @@ private void addReflectiveHierarchy(ReflectiveHierarchyBuildItem i, Type type, S
addReflectiveHierarchy(i, type.asArrayType().component(), processedReflectiveHierarchies, unindexedClasses);
} else if (type instanceof ParameterizedType) {
ParameterizedType p = (ParameterizedType) type;
addReflectiveHierarchy(i, p.owner(), processedReflectiveHierarchies, unindexedClasses);
if (!IGNORED_PARAMETERIZED_TYPE_PACKAGE_NAMES.contains(p.name().toString())) {
addClassTypeHierarchy(i, p.name(), processedReflectiveHierarchies, unindexedClasses);
}
for (Type arg : p.arguments()) {
addReflectiveHierarchy(i, arg, processedReflectiveHierarchies, unindexedClasses);
}
Expand Down
@@ -0,0 +1,14 @@
package io.quarkus.it.rest;

public class EnvelopeClass<T> {

private T content;

public EnvelopeClass(T content) {
this.content = content;
}

public T getContent() {
return content;
}
}
@@ -0,0 +1,16 @@
package io.quarkus.it.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/envelope")
public class EnvelopeClassResource {

@Path("/payload")
@GET
@Produces("application/json")
public EnvelopeClass<PayloadClass> payloadClass() {
return new EnvelopeClass<>(new PayloadClass("hello"));
}
}
@@ -0,0 +1,14 @@
package io.quarkus.it.rest;

public class PayloadClass {

private final String message;

public PayloadClass(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
@@ -1,5 +1,6 @@
package io.quarkus.it.main;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyString;

Expand Down Expand Up @@ -184,4 +185,10 @@ public void testGzipConfig() throws Exception {
.then().statusCode(413);
obj.close();
}

@Test
public void testReturnTypeWithGenericArgument() {
RestAssured.when().get("/envelope/payload").then()
.body(containsString("content"), containsString("hello"));
}
}

0 comments on commit f171059

Please sign in to comment.