Questions tagged [spring-validation]
42 questions
0
votes
2 answers
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) will be validated as BAD_REQUEST (with custom…

bmrki
- 371
- 3
- 15
0
votes
2 answers
@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")
private String projectName;
…

Shanka Somasiri
- 581
- 1
- 8
- 30
0
votes
0 answers
Is there a way to get the container object from BindingResult#FieldError
Is there a way to get hold of the parent object of the offending property? I need to use some other properties to build the error message. There is a BindingResult.getTarget() method, but my 'target' object is pretty big with deep nesting and…

kmansoor
- 4,265
- 9
- 52
- 95
0
votes
1 answer
0
votes
0 answers
String boot Application Validations not working
Hi in my Spring boot application, validation are specified correctly but they are not working. the application is firing up correctly and handler methods and view pages are working as expected, but the issue here is with the validations part, below…

Sandeep Prajapati
- 97
- 2
- 11
0
votes
3 answers
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.PARAMETER, })
public @interface StringConstraint {
…

MiGo
- 551
- 2
- 7
- 17
0
votes
0 answers
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") @Nullable Optional title) {
this.title = title;
…
0
votes
0 answers
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 reason? It is written that BindingResult must…

munknown
- 53
- 4
0
votes
1 answer
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-custom-validator
The problem we are facing is, it…
0
votes
1 answer
Fix user controlled data to construct path
I am getting blocker issue from sonarqube as I am using user controlled data to construct File path. I searched lot for the fix and found different solutions but no luck.
Code:
@RequestMapping(value = "/downloadImage", method = RequestMethod.GET)
…

Hitesh Kumar
- 512
- 1
- 8
- 27
0
votes
1 answer
Spring boot validation only working with @valid:
My Spring Boot validation only works if I use the annotation like this (I use Kotlin):
@valid:NotEmpty(message = "Please enter a value")
So for example:
data class RandomDto(
@valid:NotEmpty(message = "Please enter a value")
var…

KittyCat
- 415
- 4
- 9
- 26
-1
votes
1 answer
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 implement
@PostMapping
public void…

Nithya
- 1
- 2