From 67eb7b58b52eae6d446cda0724b3e2138068b403 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 13 Sep 2022 15:25:04 +0300 Subject: [PATCH] Properly support generic bounds for ParamConverterProvider classes Fixes: #27892 --- .../test/providers/ParamConverterTest.java | 4 ++-- .../startup/RuntimeResourceDeployment.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/providers/ParamConverterTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/providers/ParamConverterTest.java index e1f5c8fa6d979..c0c2447d651c7 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/providers/ParamConverterTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/providers/ParamConverterTest.java @@ -73,11 +73,11 @@ public String set(@QueryParam("id") Set uuids) { @Path("list") @GET - public String list(@QueryParam("id") List uuids) { + public String list(@QueryParam("id") List uuids) { return join(uuids.stream()); } - private static String join(Stream uuids) { + private static String join(Stream uuids) { return uuids.map(UUID::toString).collect(Collectors.joining(",")); } } diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java index 1306ad35f371a..45f83539204ce 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java @@ -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; @@ -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;