408 questions
0
votes
0
answers
33
views
How to report error about inner item value in list in Spring validator?
I have object that I want to validate using Spring Validator.
public record MyRequest(
List<@Valid Item> items,
// ...
)
and Item:
public record Item(
String foo,
// ...
)
Then I want to ...
1
vote
1
answer
187
views
Possible to overwrite the default validation message in Spring’s Validator?
I am learning how to effectively use the Spring’s Bean Validator in my REST project.
I have the following POJO:
public class Project {
@NotBlank(message = "%s is mandatory")
private ...
0
votes
0
answers
48
views
How to fail a trace when @Valid fails in Spring Boot
I would like to fail a trace when the validation @Valid of the request payload fails.
@Autowired MyService myService;
@PostMapping("/validate")
String question(@Valid @...
0
votes
1
answer
176
views
make javax.validation.constraints work with SpringBoot 3
I have a library that uses javax.validation.constraints and I want to use it with both SpringBoot 2 and SpringBoot 3 apps. The validation needs to happen on startup of the SpringBoot app when it in ...
0
votes
0
answers
66
views
Spring Boot (Kotlin) application: Validation and displaying of errors not working
I am following a course at my college where we build a simple SpringBoot application. This task is about validation. I handle the data exchange with several DTOs (for creating, updating and response).
...
1
vote
0
answers
83
views
SpringBoot @Valid on one field, based on the value of another field
I would like to use the SpringBoot @Valid to validate a http request field, but based on another field of the same http request.
I have the following code:
<?xml version="1.0" encoding=&...
0
votes
1
answer
53
views
unit test @Valid of springboot without having to spin up / mock the server
I would like to write some unit test to test the @Valid of SpringBoot request, hopefully, without having to spin the server.
For instance, in the "old way", one could write a piece of code ...
0
votes
1
answer
96
views
perform SpringBoot request validation based on configurable property
I would like to use @Valid from SpringBoot to perform request validation on a particular field.
However, I would like the validation on the field to be configurable. I.e, with one configuration, ...
0
votes
1
answer
57
views
Validate list inside request with springboot against [null]
My goal is to validate (fail) against a request which looks like this:
{
"title": "some title",
"foos": [null]
}
I have this straightforward code:
import jakarta....
1
vote
0
answers
52
views
How can I add a new validation rule without impacting other and parent fields?
I have a class PojoB which contains a field code and a field of class PojoA:
@Data
public class PojoB {
@Size(min = 1, max = 5)
@NotBlank()
@Pattern(regexp = "[0-9]+")
...
1
vote
1
answer
61
views
Spring group validation does not work on autowired beans
Situation
I am trying to create a autoconfiguration in which some properties must pass validation only in specific cases. I have a service MyService which requires credentials properties.username and ...
1
vote
1
answer
233
views
Spring-boot bean validation custom message for generated bean
I'm trying to add validation to a bean so I can verify its state before persisting it.
The class for the bean that requires validation is generated by the openapi-generator-maven-plugin plugin from an ...
0
votes
1
answer
560
views
Spring Boot & Jakarta Validation: Use group sequence by default
I am using Spring Boot 3 with Hibernate's Jakarta Validation. In my application, I have two groups of validations:
Default validations
Complex custom customizations that should only run if the ...
0
votes
0
answers
51
views
How Spring Validator helper method ValidationUtils works?
I am kind of new to Spring Validator and came through some educational code like this:
@Component("singerValidator")
public class SingerValidator implements Validator {
@Override
public ...
0
votes
2
answers
178
views
Spring Boot Eager Initialize ConstraintValidator Beans
Why do we see the Spring Beans related to Inbuilt and Custom validators initialized ONLY during the first request. Can this behavior be changed to initialize as part of the application startup in ...
0
votes
1
answer
158
views
Spring + Thymeleaf + Validation ignoring custom messages on validation annotations and going with their own
I have a typical Spring Boot (3.3.2) MVC application using validation and thymeleaf (3.1.2.RELEASE), and I'm finding that Thymeleaf seems to disregard the i18n messages specified in the validation ...
1
vote
0
answers
57
views
How to suppress and log custom spring boot configuration properties constraint validator violation?
For my springboot application / framework, I would like to create a custom Constraint Validator to validate Configuration Properties upon application startup. Based upon a different boolean property, ...
0
votes
0
answers
43
views
Spring MVC multiple input form validation in spring boot application
Here I have attached my project codes. I am trying to create a crude operation using input form. I have add a javascript code to add additional forms. Suppose, when I click Add Dependent button in ...
0
votes
0
answers
48
views
Binding result does not catch any errors. Why?
Im very new to the SpringBoot framework, currently i'm trying to create a working page for CRUD operations required for my project.
The problem is in my controller BindingResult wont catch any errors ...
1
vote
1
answer
125
views
I want to create an annotation that inherits from the @Size annotation, but it seems that it's not working
I created an annotation named OptimizedName to validate the user name and expected it to inherit from @Size, while still allowing the override of the min and max attributes. However, it's not working. ...
0
votes
1
answer
677
views
How to validate nested POJO with spring validator
I thought @Valid annotation would enable validation for nested POJO. But it fails with IllegalArgumentException.
I have two POJO
# EmailAddress.java
import jakarta.validation.constraints.Email;
...
0
votes
1
answer
736
views
Request field validation not performed
I'm conducting tests to validate when a field in a request body is not received, and I expect an exception to be thrown. However, Spring doesn't even return the generic error. I've generated classes ...
0
votes
0
answers
31
views
Why do I need to use @Validated in my class to get expected errors with @Positive?
I have this method:
@GetMapping
public List<BudgetForecastApi> findByHotel(@PathVariable @Positive final int hotelCode,
@RequestParam(value = "includeDeleted", defaultValue = "...
0
votes
0
answers
628
views
spring boot validation of request parameters - @NotNull is not working
I am trying to add Validation for my request parameters of my rest endpoint. I see that @NotBlank is working as expected and throwing Constraint violation exception while @NotNull is not.
import javax....
7
votes
2
answers
4k
views
How to put validation on list of String coming from request in spring boot?
I am creating Spring boot APIs and one of the API consumening data below:
class DataRequest{
@Size(min=1, max=10)
private String dataTitle;
private List<String> emails;
}
How can ...
0
votes
1
answer
672
views
Spring Boot Custom Validator Not Found Error: HV000030
Total newbie having trouble learning how to modify a spring boot application with a custom validator(maven, h2 repository, thymeleaf, not sure if this info is implied or necessary so here it is). I ...
0
votes
0
answers
25
views
Spring framework using validator after upgrade
I am upgrading the spring framework from very old version to 5.3.9. In the current Spring configuration, I have below validation framework included. In the new spring, I will not have the below info ...
0
votes
0
answers
414
views
How to get the Only the message form ConstraintViolationException
i have this code to deal with ConstraintViolationException to return only the message that in the constrains
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(BAD_REQUEST)
...
0
votes
1
answer
440
views
Spring Boot Controller Validation Metrics
I'm utilizing Spring Boot 3 with starter validation / Jakarta Validation via the Controller methods, and @Valid and @Validated annotations, and am using actuator for metrics.
There is a lot of "...
0
votes
0
answers
181
views
Spring validation on multiple levels
I have a controller where I have multiple levels of validation combined. The problem is that the validation on 'ToBeValidated' class are executed. But the '@SystemId' validation is skipped because of ...
0
votes
2
answers
541
views
How to register custom Spring validator and have automatic dependency injection?
When working with ConstraintValidators, we just need to define the class and constraint and Spring is able to detect the validators and instantiate them automatically, injecting any beans we ask for ...
0
votes
1
answer
158
views
How to accept multiple Query parameters as a list of objects in Spring validation
I am using Springboot 2.7.9 and I need to invoke a Request as below
localhost:8081/api/projects?page=2&size=3&sortBy=projectName&sortDirection=desc&sortBy=startDate&sortDirection=...
0
votes
1
answer
43
views
Spring validation for Query parameters bound to collections in Controller methods wont fetch the correct values
My PageSort Entity,
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PageSort {
private String sortBy;
@SortValueConstraint
private String sortDirection;
}
My ...
3
votes
1
answer
69
views
How can I make a Spring Validator to be detected and used automatically?
I want to validate the JSON content of a POST request in my controller.
I use @NullValue annotations and a custom Validator for a conditional validation. The input is invalid if the attribute type is ...
1
vote
2
answers
1k
views
How to pass the value from Pathvariable to a custom Validator in springboot?
I am having a custom Validator as follows:
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = CountryValidator.class)
public @interface ValidCountry {
String message() default "...
-1
votes
1
answer
293
views
Spring custom validation annotation isn't working because of null pointer exception?
I have this custom annotation interface:
@Documented
@Constraint(validatedBy = NameValidator.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface NameValidation {
...
0
votes
1
answer
609
views
@Pattern annotation does not work correctly because it runs when i saving the user to the database it validates the hashed password
I will try to force the user their password must have some constraints. So, I use @Pattern annotation to force user to enter the password according to my constraints. But the problem is i send the ...
0
votes
1
answer
524
views
Getting null from bindingResult after Spring Validator checks duplicates?
Here is my simple registration controller method for Sensor.
@PostMapping("/registration")
public ResponseEntity<HttpStatus> create(@RequestBody @Valid SensorDTO sensorDTO,
...
0
votes
1
answer
214
views
Error when requesting user registration, I can not remove the null error?
I have a problem implementing a user controller in a rest api, spring boot:
The problem is the following, it is all configured to receive the json, but when I put the json I have a return, 403 ...
0
votes
1
answer
52
views
Input values were not transmitted to the PostMapping controller
create.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</...
-1
votes
1
answer
159
views
This annotation is not allowed at this location (@Valid)
I am trying to validate the list which is passed as a parameter to a controller in spring-boot application.
I referred Baeldung doc to perform the same, below is the code snippet which i tried to ...
2
votes
2
answers
2k
views
In SpringBoot, how do I create a custom validator for a MultipartFile parameter?
I'm using Spring Boot 2.4. I have the following controller with a method that accepts a MultipartFile object.
@RestController
public class MyController extends AbstractController
...
@Override
...
-1
votes
1
answer
604
views
Validate Additional parameters in Requestbody for Springboot request and throw 400
@Data
public class Employee{
@NotNull
@NotBlank
private string id;
@NotNull
@NotBlank
private string name;
}
@RestController
@Validated
class EmployeeController{
@postMapping(consumes="json&...
0
votes
3
answers
8k
views
How can I create custom validator on Java List type?
I have one NumberConstraint as follows:
@Constraint(validatedBy = { StringConstraintValidator.class, })
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType....
3
votes
0
answers
297
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;
...
0
votes
1
answer
542
views
JUnit5 - Rest API controller having custom spring validator is failing
I have a controller that accepts path parameter called 'jobName'. The @ValidateJobName is the custom validator that validates the user input. If the input is wrong then it throws the error below
&...
0
votes
1
answer
3k
views
How to manually use org.springframework.validation.Validator validate() method?
I want to manually call validate(Object target, Errors errors) method from my validator which implements org.springframework.validation.Validator interface. When I bind that validator with @InitBinder ...
0
votes
0
answers
207
views
Validation on DTO not working from non-controllers
I have a request DTO, with nested objects as members, and one of them has an @Email validation on it.
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class MyRequest ...
1
vote
3
answers
2k
views
@NotNull not working on nested object properties in a Kotlin class even though @Valid is added
I have a spring-boot app in Kotlin. I have a model called MyModel with just two field : a, b
NotNull validation works fine on a but it doesn't work on b although I've added @valid on top of b.
So when ...
0
votes
0
answers
343
views
Is there a Reactive way to Validate Form Fields in Spring WebFlux?
I have a Spring Boot/Webflux project and would like to set a validation error if a username already exists, with a friendly message. However, if I make a non-blocking call to the database in the ...