Skip to content

Commit

Permalink
Properly support generic bounds for ParamConverterProvider classes
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 13, 2022
1 parent 5e6a3c9 commit 67eb7b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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

0 comments on commit 67eb7b5

Please sign in to comment.