hibernate-validator

Hibernate Validator, custom ResourceBundleLocator and Spring

痞子三分冷 提交于 2019-12-17 22:25:18
问题 I'm trying to override default ResourceBundleLocator in hibernate validation 4.1. So far it works perfectly, but the only examples of its usage include java code to instantiate ValidationFactory. When using a web application with spring hibernate validation is automatically configured (only the suitable hibernate validation *.jar file should exist and it is automatically used). How can i substitute ResourceBundleLocator in that scenario? I do not see any way of specyfing my custom

Control validation annotations order?

*爱你&永不变心* 提交于 2019-12-17 18:55:00
问题 i have a field that have two validation annotations @NotEmpty @Length(min=3,max=100) String firstName; i am just curious to know how hibernate is specifying the order of which validation annotation to be executed first, and if it's possible to custom that ? the reason i am asking is that if i left that field empty sometimes the first validation message displayed is for not empty and other times if i left it empty i get the validation message for the length annotation. thanks in advance. 回答1:

Hibernate validator: @Email accepts ask@stackoverflow as valid?

China☆狼群 提交于 2019-12-17 15:23:14
问题 I'm using the @Email annotation to validate an e-mail address. The issue I'm having is that it's accepting things like ask@stackoverflow as a valid e-mail address. I guess this is because they want to support intranet addresses, but I can't seem to find a flag so it does check for an extension. Do I really need to switch to @Pattern (and any recommendations for an e-mail pattern that's flexible) or am I missing something? 回答1: Actually, @Email from Hibernate Validator uses regexp internally.

getting error Caused by: java.lang.NoClassDefFoundError: javax/validation/ValidatorFactory

别来无恙 提交于 2019-12-14 03:15:17
问题 I have a spring project. When i run i get the following error SEVERE: Unable to process Jar entry [javax/validation/bootstrap/GenericBootstrap.class] from Jar [jar:file:/D:/Personal%20Work/eclipse%2032%20Bit/workspace/Java%20EE/Spring /.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps /ch17_ImplementTheViewsForContactInformation/WEB-INF/lib/validation-api-1.0.0.GA.jar!/] for annotations java.util.zip.ZipException: invalid LOC header (bad signature) at java.util.zip.ZipFile.read

No validator could be found for type: java.lang.Short

邮差的信 提交于 2019-12-13 13:29:31
问题 I have a JAXB generated class containing the following: @Pattern(regexp = "[0-9]", message = "Message details here") protected Short msgVal; When I run a JUnit test to validate an instance of that class via Hibernate, I get: javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Short . If I comment out the @Pattern constraint, the JUnitTest runs fine. Is it possible to have @Pattern constraints on Short values? If so, what am I missing? Regards, PM. 回答1:

How to customize default message for BigDecimal

假装没事ソ 提交于 2019-12-12 21:12:47
问题 Here are the models: public class myFormData { private BigDecimal trackingNumber; @Valid private List<myCustomRecord> records = new ArrayList<myCustomRecord>(); } public class myCustomRecord { //the field also appears here (for child records) private BigDecimal trackingNumber; } I have a controller method which receives this object at some point to do a save. public @ResponseBody ValidationResponse save(Model model, @Valid myFormData formData, BindingResult result, HttpSession session){ //do

@MockMvc does not work with validation annotated with @Valid

雨燕双飞 提交于 2019-12-12 16:33:06
问题 None of these solutions helped here: Spring mockMvc doesn't consider validation in my test. Added all of these dependencies, nothing helps. I use Spring Boot 2.1.2, pom.xml: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web<

Hibernate validator to validate constraints if @Constraint(validated by = {})

a 夏天 提交于 2019-12-12 15:23:22
问题 I have a Spring webapplication that uses hibernate validator for validation. I have constraint annotations that are located in a different project. I need to have validators for these constraints in my spring project because I need some services to perform validation. So the situation is: I cannot place my constraint validators in @Constraint(validatedBy = MyConstraintValidator.class) because the validator is in a different project, I cannot add a dependency because that would create a cyclic

Adding @NotNull or Pattern constraints on List<String>

[亡魂溺海] 提交于 2019-12-12 12:02:06
问题 How can we ensure the individual strings inside a list are not null/blank or follow a specific pattern @NotNull List<String> emailIds; I also want to add a pattern @Pattern("\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b.") but I can live without it.But I would definitely like to have a constraint which will check if any strings inside a list are null or blank. Also how would the Json schema look like "ids": { "description": "The ids associated with this.", "type": "array", "minItems": 1, "items"

javax.validation: Receive an error 'No validator could be found for type:'

有些话、适合烂在心里 提交于 2019-12-12 10:58:16
问题 Framework: JQuery, Spring, Hibernate, Hibernate Validator(JSR-303 Bean Validation) Platform: Windows I am trying to define a custom constraint @IdMustExist using JSR 303-Bean Validation. The purpose of the constraint is to check whether the entered id value exists in associated table. I am receiving an error 'javax.validation.UnexpectedTypeException: No validator could be found for type: com.mycompany.myapp.domain.package1.class1'. If I place @IdMustExist on a field definition of Class1 (as