Questions tagged [bean-validation]

Bean Validation, previously commonly called just "JSR-303", is an annotation based validation framework for javabean properties and parameters of arbitrary methods. Hibernate Validator is the reference implementation and the most widely used one.

Filter by
Sorted by
Tagged with
0 votes
1 answer
8 views

Exception while Initializing for Singleton DBInitService

While I was running my app, the exception was thrown as follows: 严重: Exception while loading the app 严重: Undeployment failed for context /wren6-fp 严重: Exception while loading the app : jakarta....
1 vote
0 answers
12 views

Hibernate Validator not always validating constraints of ElementType.TYPE_USE

I have defined a constraint with target TYPE_USE. When I use this annotation on a field its validator is not running. If I change the the target to FIELD then it is. Why doesn't the validator run for ...
  • 13
0 votes
0 answers
24 views

JAX-RS and Bean Validation in Kotlin: make @NotNull obsolete

The following JAX-RS code in Kotlin sufficiently well establishes that myParam is mandatory. @GET fun hello(@QueryParam("myParam") myParam: String): String = myParam At Kotlin-level myParam ...
  • 22.3k
0 votes
1 answer
88 views

Why Jakarta Validation did not automatically execute the validation and throw the exception?

I started validating a method parameter with: if notValid then throw exception, Then I realize that I can create my own annotations to validate parameters, and some minutes later I was looking for a ...
0 votes
2 answers
95 views

SpringBoot annotation @Validated

Validation is not called for ItemDTO fields. How do I make the check work for ItemDTO fields? If I completely remove the ItemDTO section from the request, then NotNull validation will work, but ...
1 vote
1 answer
94 views

Inconsistent Validation Exception Types in Spring Web REST Controllers when handling Lists and Single Entities

I am currently struggling with seemingly inconsistent behavior when dealing with request body validation in Spring REST Controllers. Validation of singular entities result in a ...
  • 145
0 votes
0 answers
50 views

Calling Validator gives NoProviderFoundException

I have the following dependencies defined in my gradle build (Spring Boot version is 2.7.7) // Spring Boot implementation group: "org.springframework.boot", name: "spring-boot-starter-...
1 vote
2 answers
78 views

How to overwrite custom exception over ValidationException?

I have written some logic and custom validation in Validator initialize method. But when exception occurs , custom exception was thrown but override by ValidationException eg. HV000032: Unable to ...
  • 4,544
0 votes
2 answers
76 views

How to get which field is failed in custom jakarta bean validation?

I added custom validation as annotation and add it to my DTO's as @UUID and it works expected. I add this annotation whenever I need to validate if a field is valid UUID. Whenever it fails it throws ...
  • 472
-4 votes
1 answer
137 views

Springboot 3.0 Jakarta field validations

As javax validations not supported in springboot 3.0. How to do field validations using Jakarta. imports import jakarta.persistence.Entity; import jakarta.persistence.NotNull; import jakarta....
0 votes
1 answer
37 views

Annotation return default key value

when we use annotation @NotNull and there is a constraint validation who happen not null return automatically his message @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) ...
1 vote
1 answer
869 views

Spring Boot 3.0 package javax.validation does not exist

I'm trying to use a method parameter validation feature supported by Bean Validation 1.1. For instance, the following method triggers the validation of the first parameter, making sure it's valid: ...
  • 21.8k
-1 votes
1 answer
300 views

Keep honoring javax.validation.constraints.* annotations when switching to jakarta?

We are migrating to spring boot 3 and with that, to jakarta-ee. I followed https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jakarta-ee , but I am not sure how to ...
  • 386
1 vote
1 answer
128 views

Micronaut custom validation Annotation does not work

I was trying to write a custom annotation to validate a field in a Micronaut project, I came across this section in their documentation Defining Additional Constraints My understanding was that is ...
1 vote
0 answers
120 views

Variable into Spring Boot class annotation

Is there a way to pass a variable from a property file to a class annotation? @MaxPeriod(firstDateField = "startDateFrom", secondDateField = "startDateTo", maxPeriod = "${...
0 votes
0 answers
84 views

how can @Max @Min @Valid works? in java

We commonly used validation check by @Valid, @Max, @Min, etc. I wonder how those work. When some object is created, with some validation annotation (@Max) how can it inject code that object with ...
  • 11
0 votes
1 answer
398 views

Java Bean Validations not working in a Spring Project

I have a Spring project and I'm looking to use a REST controller for some operation. I have a request class defined for the request body of the method. I added several NotEmpty validations to the ...
0 votes
1 answer
83 views

ConstraintValidator throws both default and custom error in BindingResult

I have some code here with a ConstraintValidator that validates an object by comparing two of its attributes. Here is the object, the annotation that is of interest to us is @ValidSmsTextLength: @...
  • 67
0 votes
1 answer
71 views

JPA (using Hibernate) doesn't execute Bean Validation

My expectation would be, that Hibernate would validate @NotNull when committing a transaction. Basically this blog post: https://thorben-janssen.com/automatically-validate-entities-with-hibernate-...
1 vote
1 answer
158 views

Error creating Bean with name 'defaultValidator'

I have an entity class InAppNotification.java that looks like this: @Entity @Table(name = "notification") public class InAppNotification { @Column(name = "inapptext") ...
0 votes
0 answers
41 views

Custom ConstraintValidator not invoked before persist

@Target({TYPE, ANNOTATION_TYPE, FIELD}) @Retention(RUNTIME) @Constraint(validatedBy = {UniqueNameValidator.class}) @Documented public @interface UniqueName { String message() default "...
0 votes
0 answers
96 views

Java Bean Validation: huge performance issue with obsolete @Valid

I ran into a performance issue with Java Bean Validation (Hibernate Validator) on a large object, which caused the validation to run several orders slower. I was able to isolate and reproduce it with ...
0 votes
1 answer
199 views

How to use hibernate-validator to validate interface parameters

I have the following code to implement interface input parameter validation and now want to use hibernate-validator to do this public class Order { private String orderNo; private String orderId;...
  • 1
0 votes
2 answers
109 views

Hibernate @OneToMany removing from Set doesn't trigger constraint validation on update of parent entity

I have the following scenario: @Entity @Table(name = "groups_supervisors") public class SupervisorEntity extends AbstractEntity { @ManyToOne @EqualsAndHashCode.Exclude @JoinColumn(...
0 votes
0 answers
109 views

Overridden java bean validation messages when validation manually invoked

I am having trouble getting overridden java bean validation messages when validation is invoked "manually". To be more precise - we are overriding standard javax validation messages by ...
3 votes
0 answers
140 views

Custom validation without annotation in spring

I have validations in my application which are built based on spring validation annotations like NotNull, NotEmpty. public class AccountCreateRequest { @NotNull private String accountName; ...
  • 1,929
0 votes
0 answers
41 views

Spring boot Bean concept in Rest API

while creating rest api in spring boot , at database end we pass the object of entities to the methods , i dont want to pass the entity i want pass the bean Please explain anyone how to create the ...
0 votes
0 answers
76 views

Jackson Bean Validation during deserialization of XML using xmlMapper

I've a xml file that I'm deserializing using Jackson XmlMapper. I wanted to do Bean validation during deserialization using javax.validation annotations like @Pattern, @Size, etc. Is there a way to ...
0 votes
0 answers
58 views

what does this BindingResult error mean in spring mvc?

I have a login button in my site's ui, which when clicked goes to the /login address, which is handled by the controller below. But when I click on this button, the following error occurs. What is the ...
1 vote
2 answers
489 views

Java generic type validation

I have a generic super class which I'd like to validate: abstract class Generic<T> { // ... other validated fields private T value; } Then I have several concrete classes and for each ...
  • 2,272
0 votes
1 answer
191 views

Camel bean-validator with group validation doesn't start for FailedToStartRouteException

I'm trying to use the camel-bean-validator dependency in my project but I have a problem with group validation. I'm using a springboot project with spring-boot-starter-parent 2.7.3 and these ...
  • 19
0 votes
0 answers
41 views

Custom Bean Validator for Method Parameter not called

I have written a bean validator to validate a method parameter of a REST service method in our Spring Boot project (Kotlin): @Target(AnnotationTarget.VALUE_PARAMETER) @Retention(AnnotationRetention....
0 votes
2 answers
395 views

Custom bean validation is not being called at all

I'm trying to create a custom bean validator, but, no matter what I do, the validator methods are not being called at all. All the other validation annotations are working perfectly. This is the ...
  • 6,406
0 votes
0 answers
127 views

Why Bean Validation in Spring Boot app always return bad request for invalid input?

I have built a custom constraint that validates some of our object fields such as telephone numbers, but when such a validation fails, let's say because of a typo, Spring Boot returns the status code ...
0 votes
0 answers
203 views

Micronaut Bean Validation with Optional Parameters

I am currently using Micronaut with the following request bean and controller: ... @Introspected public final class Bean { private final HttpRequest<?> httpRequest; @Nullable @...
4 votes
1 answer
157 views

@AssertTrue giving JSR-303 issue when using inside a nested Object on which @Valid annotation is present

My Custom DTO class is as follows : public class TestDto1 { private String key; private String val; @AssertTrue private boolean isValid() { return key !=null || val !=null; }public class ...
0 votes
0 answers
108 views

Customize property path in ConstraintViolation message

I would like to customize the property path of the ConstraintViolation error message. Example: class A{ @Valid private B b; } class B{ @NotNull private String s; } Validate A with B and a null s ...
  • 531
1 vote
0 answers
86 views

Bean Validation API / Hibernate Validator: any way to detect the requested validation groups during validation?

Indeed, this is somewhat a duplicate of a previous question, however I was wondering whether, after nine years and some new specification versions being published, the situation has changed in any way,...
0 votes
0 answers
281 views

How do I get an error message from hibernate validator in a specific language on demand?

When the hibernate validator library is used for bean validation it loads its translations from a resource bundle contained within the library: ValidationMessages_fr.properties ValidationMessages_en....
0 votes
1 answer
103 views

How do I validate an attribute of type BigDecimal using Bean Validation annotation?

I'm just wanting to do a simple validation, if the html fields below are sent "null or empty" the user can't persist the data. How can I solve this problem? below my code HTML: <div ...
  • 11
2 votes
1 answer
227 views

How to stop lombok from copying annotations to getters/setters in Eclipse?

We have a problem with running Lombok > 1.18.18 as an Eclipse Agent (2022-06 or v4.24.0)... it started copying JSR-303 Bean Validation constraints to the setters generated. We were surprised ...
0 votes
1 answer
141 views

Hibernate validator - field A or B can be empty, but both A and B cannot be empty

A bean class with multiple fields. When checking, if A is empty, check B, otherwise do not check B. And I need to set the message according to different checks. I have many such validations, can ...
  • 1
0 votes
1 answer
112 views

GenericFilterBean response error doesn't work for all endpoints

I have implemented a GenericFilterBean to filter jwt tokens : public class AuthFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest servletRequest, ...
  • 37
0 votes
0 answers
103 views

inconsistent bean validation initialization of ConstraintValidator defined via ServiceLoader

This question asks for some specifics about more general topic regarding modularization of bean validation I asked before. In question linked above, following this documentation and this post I split ...
  • 2,223
2 votes
1 answer
572 views

Java ConstraintValidator Purpose

I am trying to understand the purpose of Java's ConstraintValidator interface. It's an interface, however how does it make coding more quick or more efficient? Trying to understand benefits of using ...
0 votes
1 answer
467 views

Bean validator: validate nested object while adding a prefix to its error messages

I'm having a problem where, when I have multiple nested beans of the same type, the returned message may end up being the same, which can confuse the user: Minimal example (the real beans have lots of ...
  • 6,406
0 votes
0 answers
128 views

Get bean validator implementation generic at runtime

I want to create a generic child (nested) property validator that allows nested annotations and it works for our use case but should be more generic. We need this cause certain objects may have ...
  • 5,529
0 votes
0 answers
306 views

Java records validation fail when using byte buddy

So i'm trying to do validation of java records as its done in this article I have a custom validator for validating phone number that uses google's phone number library and i'm getting the following ...
0 votes
2 answers
303 views

Bean-Validate minimum and maximum value for LocalDate

I would like to provide bean-validation for variable which is of the LocalDate type. The minimum acceptable value should be LocalDate.of(2020,1,1). The maximum acceptable value should be LocalDate.of(...
0 votes
1 answer
52 views

Struts2 keep same action url if validation fail using struts2-bean-validation-plugin

I am using Struts 2 and I have two action one will show the register form and second will be register user. I want to achieve is while submitting form if any validation fail then user will be redirect ...
  • 21

1
2 3 4 5
38