netceteragroup / valdr-bean-validation

Java Bean Validation plugin
MIT License
35 stars 21 forks source link

Use Bean Validation metadata API for constraint retrieval #33

Open gunnarmorling opened 7 years ago

gunnarmorling commented 7 years ago

Hi, I just came across this library; nice stuff!

Exposing constraint metadata so it is consumable also from non-Java clients has been one goal of Bean Validation from day one. We actually provide an API for obtaining all the constraints from given model classes: http://beanvalidation.org/1.1/spec/#constraintmetadata.

I would suggest to use that API instead of doing your own annotation scanning. It would then not matter how constraints are declared (annotations vs. XML vs. HV's programmatic API), whether constraints are given on fields vs. getters, it resolves default validation messages, it deals with constraint composition etc.

I.e. we already do all the hard work for you :)

marcelstoer commented 7 years ago

I just came across this library

Not really, is it? You reached out to me by email in June 2016 😄

We actually provide an API for obtaining all the constraints from given model classes: http://beanvalidation.org/1.1/spec/#constraintmetadata.

Thanks for pushing Gunnar, you mentioned that in the email 😉 So, I've known for about nine months that there's room for improvement here. It's good that there's now a publicly visible issue for that.

gunnarmorling commented 7 years ago

Hi Marcel, uh oh, it had completely escaped my mind that we've been in touch before 😃 Using the meta-data API would be great; I noticed because it would return the default message key ("{javax.validation.constraints.NotNull.message}") instead of the value from the default message bundle.

I've filed https://github.com/netceteragroup/valdr/issues/119 for the message interpolation issue.