javax.validation

How do I get the real annotation instead of a proxy from ConstraintDescriptor::getAnnotation? (javax.validation Apache Bval)

本秂侑毒 提交于 2021-02-11 12:07:30
问题 I'm trying to get a Class object reference for the annotation which caused a ConstraintViolation in the javax.validation package (Apache Bval implementation). After getting some ConstraintViolations, I pass them into the following function: private Class<?> getConstraintAnnotation(final ConstraintViolation<?> constraintViolation) { return constraintViolation .getConstraintDescriptor() .getAnnotation() .getClass(); } And this returns a class object whose getName() , getCanonicalName() , and

How do I get the real annotation instead of a proxy from ConstraintDescriptor::getAnnotation? (javax.validation Apache Bval)

半城伤御伤魂 提交于 2021-02-11 12:07:25
问题 I'm trying to get a Class object reference for the annotation which caused a ConstraintViolation in the javax.validation package (Apache Bval implementation). After getting some ConstraintViolations, I pass them into the following function: private Class<?> getConstraintAnnotation(final ConstraintViolation<?> constraintViolation) { return constraintViolation .getConstraintDescriptor() .getAnnotation() .getClass(); } And this returns a class object whose getName() , getCanonicalName() , and

How do I get the real annotation instead of a proxy from ConstraintDescriptor::getAnnotation? (javax.validation Apache Bval)

二次信任 提交于 2021-02-11 12:04:28
问题 I'm trying to get a Class object reference for the annotation which caused a ConstraintViolation in the javax.validation package (Apache Bval implementation). After getting some ConstraintViolations, I pass them into the following function: private Class<?> getConstraintAnnotation(final ConstraintViolation<?> constraintViolation) { return constraintViolation .getConstraintDescriptor() .getAnnotation() .getClass(); } And this returns a class object whose getName() , getCanonicalName() , and

@Valid not working for spring rest controller

戏子无情 提交于 2020-07-10 07:01:09
问题 I have defined a rest endpoint method as: @GetMapping("/get") public ResponseEntity getObject(@Valid MyObject myObject){....} This maps request parameters to MyObject. MyObject is defined as(with lombok, javax.validation annotations): @Value @AllArgsConstructor public class MyObject { @Min(-180) @Max(180) private double x; @Min(-90) @Max(90) private double y; } But validations are not working. Even with values out of prescribed range, request doesn't throw error and goes well. 回答1: I see a

How to validate the length of elements inside List using javax.validation.constraints in Spring

南笙酒味 提交于 2020-01-05 06:59:12
问题 How to validate the length of elements inside List using javax.validation.constraints in Spring. Right now @Size is validating on the list size, not on the inside elements. class RequestInputParamaters { @NotNull @NotEmpty @Size(min = 1, max=4) List documentIdentifier_value } 回答1: Try: List<@NotNull @NotEmpty @Size(min = 1, max=4) String> documentIdentifier_value; If using hibernate-validator , you'll need version 6+. Legacy solution: @Valid List<StringWrapper> documentIdentifier_value; where