hibernate-validator

What alternatives are there to Hibernate Validator's @SafeHtml to validate Strings?

落爺英雄遲暮 提交于 2020-05-14 16:12:04
问题 As stated in the JavaDocs, it will be removed in a future release. Is there any alternative library which works similarly via annotations? 回答1: Let's first explain the reasons of the deprecation: we recently had a security issue (CVE) due to this very constraint. It was due to an error in our implementation but it made us realize that this was very fragile and potentially a can of worms security wise. The alternative for now would be to implement it yourself based on our latest implementation

Spring boot: how can I validate a multipart form in springboot

我只是一个虾纸丫 提交于 2020-04-16 05:14:14
问题 I am aware of ResultBinding when trying to validate a form (get request), i am also aware of @Valid when trying to validate a request body but i have no knowledge of validating a multipartForm Request parameter. I have a multipart form with a request parameter @RequestParam("model") String userJson of a json string representation of my User.class. when i convert the json to an object, User user = new Gson().fromJson(userJson, User.class); how can i check if the parameters in the user class

hibernate validator without using autowire

青春壹個敷衍的年華 提交于 2020-02-02 15:22:43
问题 I'am currently working on a Jersey project and decided to use Hibernate validator for the parameter validations. All dependencies injected on the Endpoint classes are properly initialized. However for those dependencies in the ConstraintValidator classes, it always throw a NPE. So i followed the guide on Spring+hibernate guide and registered bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" and used the @Autowired annotation for the services

hibernate validator without using autowire

耗尽温柔 提交于 2020-02-02 15:20:10
问题 I'am currently working on a Jersey project and decided to use Hibernate validator for the parameter validations. All dependencies injected on the Endpoint classes are properly initialized. However for those dependencies in the ConstraintValidator classes, it always throw a NPE. So i followed the guide on Spring+hibernate guide and registered bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" and used the @Autowired annotation for the services

Validation for generated JAXB Classes (JSR 303 / Spring)

…衆ロ難τιáo~ 提交于 2020-01-22 19:22:27
问题 I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin) I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema. can someone give me a nudge in the right direction on how to get this done. 回答1: We've been using the Krasa JAXB plugin to

Adding custom error messages for validation in Spring-MVC

有些话、适合烂在心里 提交于 2020-01-13 07:29:07
问题 I am using Spring-MVC and I would like to do validation tests in backend. Currently I am able to perform the tests, redirect properly to the link. But I am only unable to add custom error messages incase there is a problem, Example : "Firstname is empty". I tried using the ValidationMessages_en_EN.properties file in WEB-INF, but that also didn't help. I am posting my code, kindly let me know where I am going wrong : COntroller : @Controller public class PersonController { @RequestMapping

Spring MVC with hibernate Validator to validate single basic type

老子叫甜甜 提交于 2020-01-12 13:46:53
问题 Below is the mapped method that I am having trouble with, no matter what value I pass to it the validation returns "passed validation." @RequestMapping(value = "test", method = RequestMethod.POST) @ResponseBody public String getTest(@RequestBody @Valid @Max(32) long longValue, BindingResult result) { if (result.hasErrors()) { return "failed validation"; } else { return "passed validation"; } } I know the @Max works with my application because I use it for validation on custom objects that

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

泪湿孤枕 提交于 2020-01-11 02:34:17
问题 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

How do I import javax.validation into my Java SE project?

六眼飞鱼酱① 提交于 2020-01-10 07:53:06
问题 I'm trying to add constraints checking, as described here How to specify the cardinality of a @OneToMany in EclipseLink/JPA 回答1: Here are the dependencies I'm using (with Maven): <dependencies> <!-- Bean Validation API and RI --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.0.2.GA</version> </dependency> <

Hibernate-validator Groups with Spring MVC

自古美人都是妖i 提交于 2020-01-10 04:27:05
问题 I'm using hibernate-validator 4.3.1 and Spring MVC 3.2.3. My application has a bean with the following properties and annotations (I've removed most of them to make it simple): public class Account { @NotEmpty(groups = GroupOne.class) private String name; @NotEmpty(groups = GroupOne.class) private Date creationDate; @NotEmpty(groups = GroupTwo.class) private String role; @NotEmpty(groups = GroupTwo.class) private String profile; //getters and setters } As it is showed, there are two groups of