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

Properly support generic bounds for ParamConverterProvider classes #27898

Merged
merged 1 commit into from
Sep 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public String set(@QueryParam("id") Set<UUID> uuids) {

@Path("list")
@GET
public String list(@QueryParam("id") List<UUID> uuids) {
public String list(@QueryParam("id") List<? extends UUID> uuids) {
return join(uuids.stream());
}

private static String join(Stream<UUID> uuids) {
private static String join(Stream<? extends UUID> uuids) {
return uuids.map(UUID::toString).collect(Collectors.joining(","));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -503,7 +504,27 @@ private static void smartInitParameterConverter(int i, ParameterConverter quarku
if (genericParameterTypes[i] instanceof ParameterizedType) {
Type[] genericArguments = ((ParameterizedType) genericParameterTypes[i]).getActualTypeArguments();
if (genericArguments.length == 1) {
quarkusConverter.init(paramConverterProviders, loadClass(genericArguments[0].getTypeName()),
String genericTypeClassName = null;
Type genericType = genericArguments[0];
if (genericType instanceof Class) {
genericTypeClassName = ((Class<?>) genericType).getName();
} else if (genericType instanceof WildcardType) {
WildcardType genericTypeWildcardType = (WildcardType) genericType;
Type[] upperBounds = genericTypeWildcardType.getUpperBounds();
Type[] lowerBounds = genericTypeWildcardType.getLowerBounds();
if ((lowerBounds.length == 0) && (upperBounds.length == 1)) {
Type genericTypeUpperBoundType = upperBounds[0];
if (genericTypeUpperBoundType instanceof Class) {
genericTypeClassName = ((Class<?>) genericTypeUpperBoundType).getName();
}
}
}
//TODO: are there any other cases we can support?
if (genericTypeClassName == null) {
throw new IllegalArgumentException(
"Unable to support parameter converter with type: '" + genericType.getTypeName() + "'");
}
quarkusConverter.init(paramConverterProviders, loadClass(genericTypeClassName),
genericArguments[0],
parameterAnnotations[i]);
return;
Expand Down