54 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
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....
0
votes
2
answers
67
views
How to Validate Collection of Date with Specific Format In Spring Boot
I'm using spring data validation and i want to validate Set or List of Date but all the examples that i saw before were validating single value, Here is request class representation
...
0
votes
0
answers
44
views
How to Render Validation Messages from DTO in Thymeleaf View?
I am working on a Spring Boot project where I want to display validation error messages defined in my DTO directly on the view using Thymeleaf, especially the "content" field. While the ...
0
votes
1
answer
211
views
Validation for a collection of objects
I am writing the backend part of an application in which I want to implement the ability to accept and validate for each object in the list.
I know about two annotations that can do this:
@Valid is ...
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
0
answers
25
views
Bean Validaton : org.springframework.web.bind.MethodArgumentNotValidException
I have added validation constraints on fields of class which maps to the input fields of registration form, after invalid input I want to show same form with error message populated with it. I am ...
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;
...
2
votes
1
answer
107
views
How to throw an error message when there is no method mapping in Spring controller
How to throw an error message when there is no method mapping in Spring controller.
In the following example GET /api/v1/foos doesn't exist, is there a way to throw a generic message (say api/v1/foos ...
0
votes
1
answer
276
views
Custom validation message for Invalid Data Type Input | Spring Validation
I am working with sprinboot in a simple web application, I using the spring validation framework to validate my fields constraints.
I have a "version" field that its a float, when I enter ...
0
votes
0
answers
310
views
Spring Boot Constraint fails validating multipartFile fields with the @NotNull rule
I have a Spring boot 3.1.2 project with a "Document" entity which has a multipartFile field named "documentFile".
Im trying to endpoint-side validating it using Constraint ...
1
vote
0
answers
182
views
Custom Validation message is not working with Spring Boot 3
I am using Spring boot 3 Rest Api, with spring-validation-starter.
Even after configuring Message Source and LocalValidatorFactoryBean, as follows
@Bean
@Primary
public MessageSource ...
0
votes
1
answer
432
views
@Email annotation not working in springboot application
I have a getMapping controller which accepts emailId and Set as input.
I want to have a validation check for Non empty/blank values and email id validation, below is the sample code. @Email validation ...
0
votes
0
answers
267
views
Bean validation in Spring Webflux.fn
I'm trying to implement standard bean validation in our project which is using Spring Webflux with functional endpoints.
Spring Boot Version: 2.7.14
Spring Boot Starter Validation: 2.7.14
<...
2
votes
1
answer
75
views
Cannot use repository inside custom request class for request validations in spring boot
So I am trying to validate email and name in UserCreateRequest class but @Wired doesn't work and userRepository is null
UserCreateRequest.java:
@Getter
@Setter
@Component
public class ...
1
vote
0
answers
221
views
Ordering Spring validations using groups and exceptions
I have a controller with a post method that takes in some headers as string as well as a request body as an object.
I want to use spring validation for all of it. I currently have my headers ...
1
vote
0
answers
54
views
Validating RequestParam with multiple annotations
I have only one request param in the rest controller in spring boot 3.
I have added @NotBlank and @Size annotations for the validation of that one request param.
While validation both annotations are ...
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
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 ...
1
vote
1
answer
1k
views
Why @NotBlank not violated when leading/trailing space
This is my validation code for a field title:
@NotNull(message = "Not null")
@NotBlank(message = "Not blank")
@Size(min = 10, max = 300, message = "min 10, max 300 characters&...
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 ...
3
votes
0
answers
469
views
Jakarta / Spring Validation of Contained Values in Kotlin
I'm running into an issue validating values via a Spring Boot 3 REST API.
More specifically, I need to validate the contained values within a List Param.
Here's my API:
@GetMapping
fun getHelloWorld(
...
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 ...
1
vote
0
answers
41
views
Is this a bug in org.springframework.validation.Errors in ver 3.0.6?
Here's my method for processing the taco, I return to the design view if there's an error found.
@PostMapping
public String processTaco(@Valid Taco taco, Errors errors, @ModelAttribute ...
0
votes
1
answer
165
views
Spring Boot MVC Thymeleaf Form Validation Problem Kotlin Class
I had a problem with thymeleaf form and jakarta validation @Valid annotation and bindingResult - it didn't worked for me - I had always 0 errors
I spent a lot of time reading documentations, changing ...
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 "...
0
votes
2
answers
2k
views
Spring Validation seemed to stop working (Logging that all fields are null)
So I have an endpoint to register a user, that takes a RegisterDto with validations as RequestBody. I sadly don't know since when the validation stopped working, but at the moment even with every ...
0
votes
1
answer
220
views
Eclipse (Maven) Changes not being compiled/built by auto-reloader
I have the automatic reload enabled in Eclipse with the Maven project I'm currently working on. I've noticed that changes to the application.properties file almost never trigger an automatic reload, ...
0
votes
1
answer
765
views
How to override the message in a custom validator when the base code is unique to all the controller implementations
I have written an AbstractCRUDController class and have a getById method as shown below
public abstract class AbstractCRUDController<ENTITY extends BaseEntity, POSTDTO extends BaseDTO, PATCHDTO ...
0
votes
1
answer
70
views
How to perform a validation on an attribute only if the value of the attribute is not null
I have a search criteria for a Project model. A Project can be searched using an id or project name.
@Data
@Builder
public class ProjectSearchCriteria {
@IsNumberValidatorConstraint(message = &...
0
votes
2
answers
922
views
Spring validations -> @NotNull on nested objects with BigDecimal
I have POST endpoint that creates for example Books,
in CreateBookRequest class I have another nested class/record that holds BigDecimal price.
I want to secure this endpoint so json's (given below) ...
0
votes
2
answers
1k
views
@Pattern annotation is not validating the format
I have a projectDTO which accepts a project name and start date. See below
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProjectDTO {
@NotBlank(message = "project name is required&...
1
vote
1
answer
127
views
Why SpringBoot validation not work with single @PropertySource
My Source code:
Person.java
@Component
@Validated
@PropertySource(value = "classpath:person.yaml")
@Data
public class Person {
@NotNull(message = "test can't be null")
...
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 ...
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;
...
1
vote
1
answer
360
views
Network calls inside custom validations in spring boot
I need to validate a number of fields in my REST Api. Is there a specific pattern to do this ? My api is cluttered with these validation calls.
Check auth token in the http request against another ...
0
votes
0
answers
70
views
Spring Boot - How to apply validators to type arguments in Kotlin?
I have the following Java class in my project
public class Post {
public final @Nullable Optional<@Size(min = 10, max = 255) String> title;
public Post(@JsonProperty("title") ...
0
votes
1
answer
4k
views
Spring custom validator with dependencies on other fields
We are using spring custom validator for our request object used in our controller endpoint. We implemented it the same way as how its done in the link below:
https://www.baeldung.com/spring-mvc-...
5
votes
1
answer
3k
views
Kotlin spring boot @RequestBody validation is not triggered
I have a problem on a project with validating @RequestBody by using
implementation("org.springframework.boot:spring-boot-starter-validation")
My DTO looks like this:
import javax.validation....
1
vote
1
answer
8k
views
Spring boot rest requestbody and @valid not working when object is null/empty
I am trying to apply not null validation on an attribute of my request which is instructedAmount but it is not working. I have a Spring Boot (V2.3.0.RELEASE) application with the following endpoints:
@...
1
vote
1
answer
2k
views
openapi generates minimum and maximum which is not working properly
openapi minimum/maximum
put:
summary: add
operationId: add
requestBody:
description: value
required: true
content:
application/json:
...