0

I am trying to validate the limit parameter in the following method, but there is not any error or warning message even I enter 0 (when I enter -2, an unknown error message returned.

@RestController
@Validated // I also add this
@RequestMapping("/api/v1")
public class EmployeeController {

    @GetMapping("/employees/{limit}")
    public ResponseEntity<ApiResponse<List<Employee>>> findTopNEmployeeBySalary(
            @PathVariable("limit") @Valid @Min(1) int limit) {
        // ...
    }

}

So, what I am missing in here?

1
  • @Closures Why close? Commented Nov 25, 2022 at 10:51

1 Answer 1

0
@RestController
@Validated
public class ExampleController {
    
    @GetMapping("/{limit}")
    public void endpoint(@PathVariable @Min(1) int limit) {
        // nothing
    }
}
GET http://localhost:8080/-21

{
    "timestamp": "2022-11-24T17:21:37.375+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/-21"
}
javax.validation.ConstraintViolationException: endpoint.limit: must be greater than or equal to 1
.
.
.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for reply, but I also tried this and still not giving error and let the request to pass to the Service. May it be related to javax.validation.constraints.Min ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.