hibernate-validator

Spring 5 Webflux functional endpoints - How to perform input validation?

情到浓时终转凉″ 提交于 2019-12-01 03:20:58
According to the current doc (5.0.0.RELEASE) Spring Webflux supports validation when working with annotated controllers: By default if Bean Validation is present on the classpath — e.g. Hibernate Validator, the LocalValidatorFactoryBean is registered as a global Validator for use with @Valid and Validated on @Controller method arguments. However nothing is said about how to automate it with functional endpoints. In fact, the only example of input processing in the documentation doesn't validate anything: public Mono<ServerResponse> createPerson(ServerRequest request) { Mono<Person> person =

How to add custom error messages in Hibernate validator

会有一股神秘感。 提交于 2019-12-01 02:42:24
问题 I have a simple class like this, import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; public class Form implements Serializable { @NotNull @Length(min = 2, max = 20) private String lastName; } I have messages.properties file in the classpath. It's then loaded via Spring bean as follows, <bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource"> <ref bean=

Test Custom Validator with Autowired spring Service

点点圈 提交于 2019-12-01 01:53:25
问题 I have a custom Hibernate Validator for my entities. One of my validators uses an Autowired Spring @Repository. The application works fine and my repository is Autowired successfully on my validator. The problem is i can't find a way to test my validator, cause i can't inject my repository inside it. Person.class: @Entity @Table(schema = "dbo", name = "Person") @PersonNameMustBeUnique public class Person { @Id @GeneratedValue @Column(name = "id", unique = true, nullable = false) private

Spring MVC Validation of Inherited Classes

折月煮酒 提交于 2019-12-01 01:48:43
问题 I have a hard time believing I'm the only one who wants to do this, but I can't find any references to help me over my hurdle. Using Spring MVC and annotation-based validation (I'm using framework 4.0 and Java 1.7), consider a simple class hierarchy, as follows: abstract class Foo { @Size(max=10, message = "The name has to be 10 characters or less.") private String name; public String getName() { return this.name; } public void setName(String name) { this.name = name; } } class Bar extends

How to validate field level constraint before class level constraint?

偶尔善良 提交于 2019-12-01 00:45:19
I have a class: @ColumnNameUnique(groups = CreateTableChecks.class) public class Table { @Valid @NotEmpty(groups = CreateTableChecks.class) private List<Measure> measures; } The class level constraint @ColumnNameUnique(groups = CreateTableChecks.class) always runs first, after that the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs. Is there anyway to force the the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs first? You need to use @GroupSequence and re-define the default group sequence . Without this the validation order within a group is

Spring 5 Webflux functional endpoints - How to perform input validation?

馋奶兔 提交于 2019-11-30 23:41:54
问题 According to the current doc (5.0.0.RELEASE) Spring Webflux supports validation when working with annotated controllers: By default if Bean Validation is present on the classpath — e.g. Hibernate Validator, the LocalValidatorFactoryBean is registered as a global Validator for use with @Valid and Validated on @Controller method arguments. However nothing is said about how to automate it with functional endpoints. In fact, the only example of input processing in the documentation doesn't

Hibernate Validator and Jackson: Using the @JsonProperty value as the ConstraintViolation PropertyPath?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:50:59
Say I have a simple POJO like below annotated with Jackson 2.1 and Hibernate Validator 4.3.1 annotations: final public class Person { @JsonProperty("nm") @NotNull final public String name; public Person(String name) { this.name = name; } } And I send JSON like such to a web service: {"name": null} Hibernate when it reports the ConstraintViolation uses the class member identifier "name" instead of the JsonProperty annotation value. Does anyone know if it is possible to make the Hibernate Validator look at the annotation of the class and use that value instead? No, that's not possible. Hibernate

Hibernate validation “Unable to initialize javax.el.ExpressionFactory” error

余生颓废 提交于 2019-11-30 20:40:19
I'm trying to use hibernate validation, code compiles, but when launched in fails with error: Exception in thread "main" javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead Code: import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; public class Run { public static void main(String[] args) { User u = new User(); ValidatorFactory factory =

error: No validator could be found for type: java.time.LocalDate

十年热恋 提交于 2019-11-30 18:07:53
I'm working on a project that uses bean validation (Hibernate Validator 5.1.3.Final). My bean has a attribute with the @Past annotation. @Past(message = "A data deve estar no passado.") private LocalDate dataAbertura; But, when the validation occurs I get the following exception: 21:46:12,424 ERROR [io.undertow.request] (default task-35) UT005023: Exception handling request to /financeiro/clientes/pessoafisica: javax.servlet.ServletException: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.time.LocalDate. at br.com.caelum.vraptor.VRaptor.doFilter

error: No validator could be found for type: java.time.LocalDate

假装没事ソ 提交于 2019-11-30 16:50:17
问题 I'm working on a project that uses bean validation (Hibernate Validator 5.1.3.Final). My bean has a attribute with the @Past annotation. @Past(message = "A data deve estar no passado.") private LocalDate dataAbertura; But, when the validation occurs I get the following exception: 21:46:12,424 ERROR [io.undertow.request] (default task-35) UT005023: Exception handling request to /financeiro/clientes/pessoafisica: javax.servlet.ServletException: javax.validation.UnexpectedTypeException: HV000030