bean-validation

How to test a Validator which implements ConstraintValidator in java?

…衆ロ難τιáo~ 提交于 2020-08-04 02:32:47
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to test a Validator which implements ConstraintValidator in java?

為{幸葍}努か 提交于 2020-08-04 02:32:37
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to do Bean Validation with Hibernate Validation in Spring Boot app?

萝らか妹 提交于 2020-07-03 12:58:08
问题 I'm learning about Hibernate Validation in a Spring Boot app and I have a Rest controller and a POST method. And when I make a request, if a field isn't validated successfully, the client should receive 400 Bad Request and in the body a message like this "validation failed". And I try to do this, but the message didn't come. This is the Body: { "timestamp": "2020-06-06T07:56:11.377+00:00", "status": 400, "error": "Bad Request", "message": "", "path": "/ibantowallet" } And in the console logs

java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName

会有一股神秘感。 提交于 2020-06-13 15:29:47
问题 JDK: 1.8.0_131 Tomcat: 8.0.27.0 Hibernate Validator: 6.0.7.Final + all the dependencies downloaded from: Hibernate Validator 6 @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public AccountSyncResponse excute(AccountSyncRequest account_sync_request_) { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<AccountSyncRequest>> violations = validator.validate(account_sync

Is NotNull needed on Kotlin?

假如想象 提交于 2020-05-27 05:34:27
问题 I have a class: class User( var name: String ) And a mapped post request: @PostMapping("/user") fun test(@Valid @RequestBody user: User) { //... } What if a client will send a JSON of a user with name: null ? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name with @NotNull ? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null) ). 回答1: You can avoid using @NotNull , as it'll never get triggered

Is NotNull needed on Kotlin?

浪子不回头ぞ 提交于 2020-05-27 05:33:50
问题 I have a class: class User( var name: String ) And a mapped post request: @PostMapping("/user") fun test(@Valid @RequestBody user: User) { //... } What if a client will send a JSON of a user with name: null ? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name with @NotNull ? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null) ). 回答1: You can avoid using @NotNull , as it'll never get triggered

Is NotNull needed on Kotlin?

我怕爱的太早我们不能终老 提交于 2020-05-27 05:33:33
问题 I have a class: class User( var name: String ) And a mapped post request: @PostMapping("/user") fun test(@Valid @RequestBody user: User) { //... } What if a client will send a JSON of a user with name: null ? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name with @NotNull ? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null) ). 回答1: You can avoid using @NotNull , as it'll never get triggered

JSR-303 validation in Spring controller and getting @JsonProperty name

蓝咒 提交于 2020-05-15 02:45:05
问题 I do validation with JSR-303 in my Spring app, it works as needed. This is an example: @Column(nullable = false, name = "name") @JsonProperty("customer_name") @NotEmpty @Size(min = 3, max = 32) private String name; And REST API clients use customer_name as name of input field that send to API bud validation field error org.springframework.validation.FieldError returns name as name of the field. Is there some way hot to get JSON-ish name that is specified in @JsonProperty ? Or do I have to

JSR-303 validation in Spring controller and getting @JsonProperty name

我怕爱的太早我们不能终老 提交于 2020-05-15 02:44:58
问题 I do validation with JSR-303 in my Spring app, it works as needed. This is an example: @Column(nullable = false, name = "name") @JsonProperty("customer_name") @NotEmpty @Size(min = 3, max = 32) private String name; And REST API clients use customer_name as name of input field that send to API bud validation field error org.springframework.validation.FieldError returns name as name of the field. Is there some way hot to get JSON-ish name that is specified in @JsonProperty ? Or do I have to

Validating JAX-RS resources and methods (IBM JAX-RS implementation) using bean validation on Websphere Application Server 8.5.5

强颜欢笑 提交于 2020-03-06 09:12:43
问题 I am using IBM JAX-RS implementation to develop my REST APIs. I am looking to include validation of resource method parameters using Bean Validation (annotations) support provided in JAX-RS 2.0. I know that Jersey implementation supports this feature (https://jersey.java.net/documentation/latest/bean-validation.html). Is there a similar support available with IBM JAX-RS implementation on WAS 8.5.5? If so could you please direct me to some tutorial on how to accomplish this? I am specifically