bean-validation

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

Bean validation specification prioritizing

独自空忆成欢 提交于 2020-01-15 09:24:28
问题 I am using bean validation specification to validate my form on spring-boot thymeleaf project. My entity property is as follow. @NotEmpty(message = "{Password should not be empty}") @Pattern(regexp = //Pattern for range 1-20, message = "{Wrong Input}") private String password; When I run and inputed to password field of my form with empty value, both of Validation Error Messages were shown. My expectation is, while empty value is inputed, only @NotEmpty annotation should work and on the other

javax validation on nested object with groups

為{幸葍}努か 提交于 2020-01-15 05:55:29
问题 Here is my java code class AbstractO{ public interface Save{}; // for groups public interface Update{}; // for groups } class A extends AbstractO{ public Integer id; @NotNull(groups={A.Save.class}) @Valid public B b; } class B extends AbstractO{ @NotNull(groups={B.Update.class}) public Integer id; @NotNull(groups={A.Save.class}) public Integer prop } // controller method @ResponseBody public ResponseEntity<A> save(@RequestBody @Validated(value = { A.Save.class }) A , BindingResult

Spring webflux bean validation not working

匆匆过客 提交于 2020-01-13 08:57:27
问题 I am trying to use bean validation in Webflux. This is what I have so far: @PostMapping("contact") fun create(@RequestBody @Valid contact: Mono<Contact>) : Mono<Contact> { return contact.flatMap { contactRepository.save(it) } .doOnError{ Error("test") } } The The validation doesn't work... I would expect that the Error("test") would be shown... Does someone has a working example(Java or Kotlin)? UPDATE Here is a repository so it can be reproducted: https://github.com/jwz104/webflux-validation

Spring webflux bean validation not working

偶尔善良 提交于 2020-01-13 08:57:05
问题 I am trying to use bean validation in Webflux. This is what I have so far: @PostMapping("contact") fun create(@RequestBody @Valid contact: Mono<Contact>) : Mono<Contact> { return contact.flatMap { contactRepository.save(it) } .doOnError{ Error("test") } } The The validation doesn't work... I would expect that the Error("test") would be shown... Does someone has a working example(Java or Kotlin)? UPDATE Here is a repository so it can be reproducted: https://github.com/jwz104/webflux-validation

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> <

Is there a way to get a variable in to a custom ConstraintValidator when using JAX-RS?

天涯浪子 提交于 2020-01-06 05:36:10
问题 When de-serializing a JSON payload i want to validate a phone number using a custom validator. This validator needs to know what country the customer is in to correctly parse the phone number. The country i can find in the http header Accept-Language. The problem is how can i provide the custom validator with this extra meta data? I was sure that @Context would inject the HttpHeaders into the PhoneNumberValidator but this does not work: @Context private HttpHeaders mHttpHeaders; The field is

Validation where to organize in web app for more efficient way

两盒软妹~` 提交于 2020-01-05 10:08:29
问题 I'm thinking about validation of my web application. Here is to approaches. 1) Make validation with Spring Validator implement interface 2)Use JSR-303 on domain model. First approach looks more nicer like I can use messages to render errors on any languages and can do more complex logic. But hibernate docs shows that JSR-303 more preferable as for hibernate, I'm thinking I already identified my entity with annotation mapping and put more for validation JSR 303 it won't be much? Maybe I should

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

Make custom hibernate validation annotation for email existence

蓝咒 提交于 2020-01-04 05:35:41
问题 i was wondering if it's possible to make custom hibernate validation annotation that will check in the database if the email exist or not (call dao method and return true if the email exist) so i can do something like: @NotBlank(message = "email is required") @Email(message = "{invalid.email}") @EmailExist(message = "{email.exist}") @Column(name = "email", length = 155, nullable = false) private String email; please advise with a sample if possible, thanks in advance. 回答1: Yes it should be