How to still validate javax.validation annotated classes? #48447
-
I'm running into an issue with Quarkus 3.21.3 where I need to validate model classes from an external library that are (still) annotated using the I came up with the idea of adding constraints programmatically to these classes by implementing a Even beans that are added using the From my understanding this means that I am not able to validate the beans of my model nor any other bean that doesn't have any of the mentioned annotations, even if I programmatically add constraints using a Do I miss something here? Is there any way of getting my external beans validated? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
If I were you, I would build a small Quarkus extension that rewrites the library bytecode. It would be done at build time once and for all. See https://quarkus.io/guides/building-my-first-extension for a guide on how to create your first extension. Then your extension would be basically a build step similar to: https://github.com/quarkusio/quarkus/blob/3.15/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/JakartaEnablement.java . It uses the Eclipse Transformer to rewrite things (make sure you have a look at its options to rewrite the right package). I'm pretty sure listing the classes would be annoying, so what could could do instead is index the library with Jandex and inject a You can also find some information about how to index the library here: https://quarkus.io/guides/cdi-reference#how-to-generate-a-jandex-index . You can get all the built-in constraints from Hibernate Validator with It should be very simple so if you hit a wall, don't hesitate to ping me here. |
Beta Was this translation helpful? Give feedback.
-
I decided to write and use an extension to transform the |
Beta Was this translation helpful? Give feedback.
-
@gsmet @marko-bekhta I've set up an application to reproduce the issue at https://github.com/roamingthings/javax-validation-test |
Beta Was this translation helpful? Give feedback.
I decided to write and use an extension to transform the
javax.validation
references tojakarta.validatoin
. Unfortunately, I was not able to get the Hibernate validator that is initialized by the Quarkus extension to recognize the transformed classes. So for now, I'm creating a second validator with the 'plain' factory provided by Hibernate validation. Also this may not be an optimal solution I had to somehow proceed and for now this works for me.