Questions tagged [javax.validation]

105 questions
3
votes
1 answer

@Valid does not work for nested object in bean class in spring

I have a Bean class which has one nested object like below. import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import javax.validation.Valid; import javax.validation.constraints.NotNull; @Data …
Anjali
  • 1,623
  • 5
  • 30
  • 50
3
votes
1 answer

How to validate the length of elements inside List using javax.validation.constraints in Spring

How to validate the length of elements inside List using javax.validation.constraints in Spring. Right now @Size is validating on the list size, not on the inside elements. class RequestInputParamaters { @NotNull @NotEmpty …
2
votes
1 answer

Spring Boot - How to validate incoming nested JSON request object fields with javax.validation

I am using Spring Boot (2.7.6) and javax.validation and swagger v3. My request JSON body of this form { "itemDescription":"vehicle", "itemVersion":0, "itemCode":{ "codeType":"1", "codeValue":"1111" } } The above JSON…
cd491415
  • 823
  • 2
  • 14
  • 33
2
votes
0 answers

Swagger (@Schema(required = true)) override the javax.validation message

We have introduced swagger to our existing spring rest application. We already had javax.validation's @NotNull to validate the payload, which was working fine. After we introduce Swagger 3, we used @Schema(required = true) along with @NotNull. Now…
sathees
  • 193
  • 2
  • 3
  • 10
2
votes
1 answer

How to validate @NoNull first then @AssertTrue after

I am trying to validate a simple DTO: @Data public class Dto { @NotNull private Integer anInt; @AssertTrue public boolean isIntCustomValid() { return anInt == 123 || anInt == 999; } } In my Controller, with @Valid.…
jim jones
  • 21
  • 1
2
votes
1 answer

Multiple javax.validation.constraints validations on @PathVariable

I am applying multiple validations on path variable @PathVariable(name = "id") @NotBlank(message = "Missing required field") @Size(min = 1, max = 3, message = "Invalid input size") String id Now, when I am sending empty string in path param…
2
votes
1 answer

How to group request javax validations?

I have test spring-boot-starter-validation behaviour and noticed that: request body is validated first throwing a WebExchangeBindException and then request path&query parameters are validated throwing a ConstraintViolationException. So, how to join…
2
votes
0 answers

conditional javax.validation.constraints.Pattern

I want to turn off javax.validation.constraints.Pattern for certain conditions. It is used in field address.postcode to validate postcode pattern. But when address is non-uk then this should be turned off. We can know whether it is non-uk postcode…
Sammy Pawar
  • 1,201
  • 3
  • 19
  • 38
2
votes
2 answers

How to use @Digits validation on integer value

I want to validate if incoming number is integer value (wihout fraction), between 0 and 100. I have dto with javax.validation annotations: @Min(value = 1, message = "some msg") @Max(value = 100, message = "some msg") @Digits(integer = 3, fraction =…
enyoucky
  • 103
  • 1
  • 9
2
votes
1 answer

Executing specific group of javax validations

In my application I have an endpoint, that gets a JSON of this Object, which then calls calculateSomething() to return the number as a http response. I'm validating those values with javax.validation. Now is there a possible way for me, to specify…
xXsar_toXx
  • 23
  • 4
2
votes
3 answers

why isn't @NotBlank not showing up as an import

Having an issue with my code package com.example.demoSpring.student; import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.lang.NonNull; **import javax.validation.constraints.NotBlank;** import java.util.UUID; public…
2
votes
4 answers

javax.validation 2.0.1 List not working in spring boot
I am new the spring boot developement. I am trying to validate the post request by passing List from @RequestBody. Below is control class @CrossOrigin @RestController @RequestMapping("/webapi/device") @Validated public class DeviceController extends…
Srikanth
  • 584
  • 1
  • 6
  • 21
2
votes
0 answers

Annotations on wildcard type parameters in Kotlin

I'm looking to create a ValueExtractor for validation and been following documentation here: https://docs.jboss.org/hibernate/beanvalidation/spec/2.0/api/javax/validation/valueextraction/ValueExtractor.html The class in Java requires @ExtractedValue…
Andrejs
  • 26,885
  • 12
  • 107
  • 96
2
votes
2 answers

Validation of request body AND request parameter in 1 step?

a question to validation of put calls to a REST endpoint using spring boot and javax.validation (not the spring validation). You have the following method in the resource: @PutMapping(...) public Response getResult(@RequestBody @Valid myBody,…
kibu Kuhn
  • 81
  • 5
2
votes
1 answer

How to validate parameters of a static method in JUnit?

I have a static method with parameters and constraints. I want to run some unit tests but when I call executableValidator.validateParameters, no violations issues are raised (it should be) I run some reflection code and I display correctly the…
Jon Leb
  • 37
  • 1
  • 9