How can i validate my path variable in spring. I want to validate id field, since its only single field i do not want to move to a Pojo
@RestController
publi
To archive this goal I have apply this workaround for getting a response message equals to a real Validator:
@GetMapping("/check/email/{email:" + Constants.LOGIN_REGEX + "}")
@Timed
public ResponseEntity isValidEmail(@Email @PathVariable(value = "email") String email) {
return userService.getUserByEmail(email).map(user -> {
Problem problem = Problem.builder()
.withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE)
.withTitle("Method argument not valid")
.withStatus(Status.BAD_REQUEST)
.with("message", ErrorConstants.ERR_VALIDATION)
.with("fieldErrors", Arrays.asList(new FieldErrorVM("", "isValidEmail.email", "not unique")))
.build();
return new ResponseEntity(problem, HttpStatus.BAD_REQUEST);
}).orElse(
new ResponseEntity(new UtilsValidatorResponse(EMAIL_VALIDA), HttpStatus.OK)
);
}