Questions tagged [javax.validation]

105 questions
2
votes
1 answer

Custom Messages when Validating Object Graphs/Collections with Java Bean Validation

Observe the Following Code. A DealerLot has a carInventory, which consists of cars, all of which contain an engine. The current dealerlot has two cars in inventory, and when validated one of the car's engines fails validation. However the error…
2
votes
1 answer

javax.validation.ConstraintDeclarationException: HV000131. Cascaded validation in hierarchical objects

I have the next hierarchy: public class A extends B { @Valid public A(String languageCode, C token) { super(languageCode, token); } } The B class has a property call language code that should be validated with @NotEmpty only if a…
2
votes
1 answer

Spring boot : Error creating bean with name 'methodValidationPostProcessor'

I have a spring boot application and i am creating war file and deploying on Tomcat 8. The code works perfectly well when running in my Eclipse Oxygen and i am getting below exception when running application on Tomcat8. Caused by:…
Aditya Ekbote
  • 1,493
  • 3
  • 15
  • 29
1
vote
1 answer

javax.validation.constraints with custom Code and Message

I am using the javax.validation.constraints.NotEmpty library to validate POJO class for rest request. Within class i have used below annotaion. @ApiModelProperty(value = "Name", required = true) @NotEmpty(message = "Name is required") private String…
Zia
  • 1,001
  • 1
  • 13
  • 25
1
vote
0 answers

Annotation for validating a parameter in a record constructor is not working when @Target is specified as RECORD_COMPONENT

The ElementType.RECORD_COMPONENT, when applied to annotation for constructor parameter of a record does not work as I would anticipate. I have this record: public record MyRecord ( MultipartFile document ) {} I want to ensure that document is…
1
vote
2 answers

How to implement exception handler for javax.validation.ConstraintViolationException in Spring boot GraphQL?

How to implement exception handler for javax.validation.ConstraintViolationException in Spring boot GraphQL? I am getting following response { "errors": [ { "message": "INTERNAL_ERROR for a7027473-59c3-b9ad-1917-873f354a352d", …
Thirumal
  • 8,280
  • 11
  • 53
  • 103
1
vote
0 answers

How to add domain object's ID to validation message?

I have a Spring Boot application, which uses annotations from javax.validation to validate my domain object. Unfortunately, the error message doesn't contain the ID of the domain object. I need the ID for operation and development…
dur
  • 15,689
  • 25
  • 79
  • 125
1
vote
2 answers

SpringBoot @RequestBody validation of abstract class

I am trying to simulate the oneOf construct from OpenAPI spec in my spring-boot application. I have an abstract class Apple @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "color") @JsonSubTypes({ @JsonSubTypes.Type(value =…
Poklakni
  • 193
  • 2
  • 10
1
vote
1 answer

Java validation: Cannot interpolate field name in validation message

I tried the approach mentioned on How get property name in a validation message, but cannot apply it to the following situation. @Data public class CompanyRequest { @PositiveOrZero(message = "validation.amount.positiveOrZero") int…
user17888319
1
vote
0 answers

JAX-RS ExceptionMapper not catch javax.validation.ConstraintViolationException

I have started using javax.validation's @Valid annotation to validate data arriving at my REST endpoints. This is working as expected and throwing applicable exceptions: Caused by: javax.validation.ConstraintViolationException: Validation failed for…
Bend
  • 304
  • 1
  • 2
  • 15
1
vote
0 answers

Problem with javax validation to get error messages with assigned fields

Hello I'm a beginner in Java and I have problem with javax validation using SpringBoot. I created my own ExceptionHandler to handle validation exception: MethodArgumentNotValidException which is thrown when request is invalid. Invalid JSON request…
1
vote
2 answers

How to use @NotEmpty by combining 2 fields?

I have the following request. @Data public class ProductRequest { @NotEmpty private String code; @NotEmpty private String name; } I use this request for 2 different methods and both of them use only one field, not need the other…
user17186249
1
vote
1 answer

How to set @NotEmpty annotation messages in Spring?

In a Java (+ Spring Boot) project, there is a notation using javax.validation as shown below: @NotEmpty(message = "validation.product.notEmpty") private String product; @NotEmpty(message = "validation.username.password") private String…
user16409822
1
vote
1 answer

Javax Validation is not stable if two or more annotation satisfies the condition on same field

I have observed one issue when I have applied the two validation annotations and both are checking the same conditions in some particular scenario, javax validation output is not stable. Here is the code example: @NotBlank(message = "Date…
akhil singhal
  • 111
  • 1
  • 7
1
vote
1 answer

Validate request with List as a field with javax.validation

I am using javax.validation for validating request in an API developed using spring. I have to validate List so that all values must be a positive number and size of the list must be exactly equal to some fix number e.g. 2. public class…
Atul Kumar
  • 99
  • 8