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

Register enclosing class for reflection when used as JAX-RS return type #3557

Merged
merged 1 commit into from
Aug 20, 2019
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
@@ -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);
geoand marked this conversation as resolved.
Show resolved Hide resolved
}
for (Type arg : p.arguments()) {
addReflectiveHierarchy(i, arg, processedReflectiveHierarchies, unindexedClasses);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}