From 2d5a24337691caa6ae8e327c6cb22cb3d8507ecd Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Tue, 20 Aug 2024 15:10:43 +0200 Subject: [PATCH] Normalize CDIWrappers to an interface that they implement for Validator --- .../ArcProxyBeanMetaDataClassNormalizer.java | 11 +++++++++++ .../pom.xml | 4 ++++ .../validator/TestInterfaceRestClient.java | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TestInterfaceRestClient.java diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/ArcProxyBeanMetaDataClassNormalizer.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/ArcProxyBeanMetaDataClassNormalizer.java index 03d66360d2db5..9f8921e4741ec 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/ArcProxyBeanMetaDataClassNormalizer.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/ArcProxyBeanMetaDataClassNormalizer.java @@ -15,6 +15,9 @@ */ public class ArcProxyBeanMetaDataClassNormalizer implements BeanMetaDataClassNormalizer { + private static final String CDI_WRAPPER_SUFFIX = "$$CDIWrapper"; + + @SuppressWarnings("unchecked") @Override public Class normalize(Class beanClass) { Class targetClass = beanClass; @@ -24,6 +27,14 @@ public Class normalize(Class beanClass) { while (ClientProxy.class.isAssignableFrom(targetClass)) { targetClass = targetClass.getSuperclass(); } + if (beanClass.isSynthetic() && beanClass.getSimpleName().endsWith(CDI_WRAPPER_SUFFIX)) { + String nameToFind = beanClass.getName().substring(0, beanClass.getName().length() - (CDI_WRAPPER_SUFFIX.length())); + for (Class anInterface : targetClass.getInterfaces()) { + if (nameToFind.equals(anInterface.getName())) { + return (Class) anInterface; + } + } + } return targetClass; } diff --git a/integration-tests/hibernate-validator-resteasy-reactive/pom.xml b/integration-tests/hibernate-validator-resteasy-reactive/pom.xml index e97d2598faa5d..874a79d3c38a5 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/pom.xml +++ b/integration-tests/hibernate-validator-resteasy-reactive/pom.xml @@ -22,6 +22,10 @@ io.quarkus quarkus-rest-jaxb + + io.quarkus + quarkus-rest-client + io.quarkus quarkus-hibernate-validator diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TestInterfaceRestClient.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TestInterfaceRestClient.java new file mode 100644 index 0000000000000..07dc39c23b6c0 --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TestInterfaceRestClient.java @@ -0,0 +1,19 @@ +package io.quarkus.it.hibernate.validator; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.groups.ConvertGroup; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@RegisterRestClient +@Path("/test") +public interface TestInterfaceRestClient { + @POST + @Consumes({ "application/json" }) + Response doSomething(@Valid @ConvertGroup(to = Error.class) @NotNull String myParameter); +}