Questions tagged [javax.validation]
105 questions
0
votes
1 answer
How to get javax.validation errors messages and check this messages on HTTP 400 error test?
I'm using the javax.validation in my objects and in my annotation I have the errors messages like this:
@NotNull(message = "This name can't be a null parameter")
private String name;
When I use the @Valid on my endpoint the java will check my…

Lucas Alves
- 23
- 1
- 9
0
votes
2 answers
Could not commit JPA transaction due to javax.validation.ConstraintViolationException
I am facing an issue while performing a database update with hibernate. When trying a repository.add(Object) operation, it gives a validation exception.
I have added validation on the model class, but the values that I try to insert appears to be…

Patrick C.
- 1,339
- 3
- 16
- 31
0
votes
0 answers
Spring - @Pattern regexp value from YAML file. (Javax | Hibernate)
Trying to read regex values from yaml file in POJO class. like this,
@Pattern(regexp = "${something.value}")
private String someValue;
But this is not working because its expecting below, (Within annotations you can only refer to constant…

Satscreate
- 495
- 12
- 38
0
votes
1 answer
Hibernate Validator Depends on
Is there a way to achieve depends on behavior with hibernate validation. For instance if i have two custom validations
@InvalidAmount // Validates the amount is invalid with some custom logic
@AmountNotAccepted // Validates the currency is not…

Adiant
- 859
- 4
- 16
- 34
0
votes
0 answers
How to use Mockito to mock a class in a way that it passes javax validation
Given a class:
public class Foo {
@NotNull
@Valid
private Bar bar;
// plus getter/setter
}
Suppose I want to test that after the bar field is set, the class is now valid.
In my test, I'm using Mockito to get a fake Bar…

Eric Wilson
- 57,719
- 77
- 200
- 270
0
votes
1 answer
javax.validation.ValidationException: HV000028: Unexpected exception during isValid in Test
I can't figure out how to write a Unit Test for a Custom Constraint Validator. I have the following Validator class :
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class SchoolIdValidator implements ConstraintValidator…

Pierre Jones
- 620
- 1
- 11
- 24
0
votes
0 answers
Why @Valid annotation not working when used inside service method argument but works for controller method?
I am having this UserDto class which I want to put under @Valid
@Getter @Setter
public class UserDto{
@NotEmpty(message = "Name cannot be empty")
private String name;
@NotNull(message = "Provide a valid age")
private Integer age;
}
I…

The Coder
- 3,447
- 7
- 46
- 81
0
votes
1 answer
Is there a way to implement custom validation on spring-cloud message for individual consumers?
I'm working in a spring-cloud environment. The company has decided to pull all common code into a common module (.jar) to be added as a dependency to all applications. All the applications are consumers of a common message. I have been tasked…

stirling
- 143
- 2
- 3
- 8
0
votes
1 answer
How to apply validation to elements of a collection type
I'm using spring, and thus javax.validation, so that's context of this question.
Suppose I want to validate that the elements of a list only contain 4 digit numbers.
I would like to code:
@Min(1000)
@Max(9999)
List numbers;
but validation…

Bohemian
- 412,405
- 93
- 575
- 722
0
votes
1 answer
Hibernate Validator doesn't validate method parameters annotated with constraint annotations
I have a pojo, which is common for multiple services and each of them has different validation rules for that object. So, I am extending that pojo in each of my services and override some of the setters and throw constraint validations on those…

Ihor M.
- 2,728
- 3
- 44
- 70
0
votes
2 answers
Using javax.validation validate the date must not be less than 1900-01-01
i have a class which is working as the request payload for my api . I need to validate the one of my field "dateOfBirth". Using the javax.validation.past i am checkking the date is not future date but i also want to validate that the date must…

Prabhat Yadav
- 1,181
- 6
- 18
- 29
0
votes
1 answer
Spring Boot custom constraint validation component
config class
@ComponentScan(basePackages = {"validator"})
class AppConfiguration { ... }
annotation class
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy =…

jahoza
- 49
- 6
0
votes
1 answer
How do I get the real annotation instead of a proxy from ConstraintDescriptor::getAnnotation? (javax.validation Apache Bval)
I'm trying to get a Class object reference for the annotation which caused a ConstraintViolation in the javax.validation package (Apache Bval implementation).
After getting some ConstraintViolations, I pass them into the following function:
private…

A Frayed Knot
- 476
- 5
- 20
0
votes
0 answers
Diff b/w @NotNull annotation and nullable in @Column
I have created a model with the following field
@NotNull
@Column(name = "postal_code")
private String postalCode;
When I try to post a JSON without the postal code, It should not be saved to the database. That's the reason I have used…

ark
- 3,707
- 5
- 21
- 36
0
votes
4 answers
hibernate validator: validate 2 fields match
I was wondering, am I overlooking something or does the hibernate validator offer no annotation to verify that 2 fields are equal (such as a password).
I know I can write my own validators, but well this seems like standard functionality.

jack
- 1,902
- 5
- 32
- 43