hibernate-validator

ConstraintViolationException handler isn't executed in Micronaut

扶醉桌前 提交于 2021-02-19 03:48:04
问题 I have a ConstraintViolationException handler class that looks like this: @Produces @Singleton @Requires(classes = {ConstraintViolationException.class, ExceptionHandler.class}) public class ConstraintsViolationsExceptionHandler implements ExceptionHandler<ConstraintViolationException, HttpResponse> { @Override public HttpResponse handle(HttpRequest request, ConstraintViolationException exception) { return HttpResponse .status(HttpStatus.FORBIDDEN) .contentType(MediaType.APPLICATION_JSON)

Manually call Spring Annotation Validation Outside of Spring MVC

霸气de小男生 提交于 2021-02-11 06:58:31
问题 I have the following test that fails: @Test public void testValidation() { Validator validator = new LocalValidatorFactoryBean(); Map<String, String> map = new HashMap<String, String>(); MapBindingResult errors = new MapBindingResult(map, Foo.class.getName()); Foo foo = new Foo(); foo.setBar("ba"); validator.validate(foo, errors); assertTrue(errors.hasFieldErrors()); } Foo is as follows: import javax.validation.constraints.Size; public class Foo { @Size(min=9, max=9) private String bar; // ..

Generating a error code per property in Hibernate Validator

本秂侑毒 提交于 2021-02-07 05:53:29
问题 I am looking at using Hibernate Validator for a requirement of mine. I want to validate a JavaBean where properties may have multiple validation checks. For example: class MyValidationBean { @NotNull @Length( min = 5, max = 10 ) private String myProperty; } But if this property fails validation I want a specific error code to be associated with the ConstraintViolation, regardless of whether it failed because of @Required or @Length, although I would like to preserve the error message. class

How to return a custom response pojo when request body fails validations that are defined using Bean Validation/Hibernate Validator?

馋奶兔 提交于 2021-02-04 18:59:28
问题 Is it possible to override the default response POJO of Spring Hibernate validator? Currently when a validation gets failed then a very big response returned to the client as shown below. But I don't want the client to provide the full error response of hibernate validator and instead to send some key-value pair regarding the error message. { "timestamp": "2018-05-28T18:12:56.705+0000", "status": 400, "error": "Bad Request", "errors": [ { "codes": [ "NotBlank.abc.xyz", "NotBlank.xyz",

Android and Hibernate Validator - it is possible to use together?

醉酒当歌 提交于 2021-01-28 00:03:51
问题 I wonder if it is possible to use Hibernate Validator on Android. I tried but it looks like some javax packages are missing on Android platform (javax.xml.stream.XMLInputFactory). Here is my code, dependency and error: ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); Validator validator = validatorFactory.getValidator(); compile 'org.hibernate:hibernate-validator:5.1.3.Final' compile 'javax.el:javax.el-api:2.2.4' compile 'org.glassfish.web:javax.el:2.2.4' 03-28