I wonder how to add validation for parameter type: I have endpoint:
@PostMapping(consumes = "application/json", path = "/v2/tw")
@ResponseStatus(HttpStatus.CREATED)
public TwDto add(
Authentication auth,
@Validated(TwDto.New.class) @RequestBody TwDto twDto,
BindingResult bindingResult) {
TwDto has inside
@Valid
@PositiveOrZero
@Pattern(regexp = "[0-9]", message = "id must be a number")
private Long storeId;
When I set storeId = "123someString"
then I get alwasy 400 error without any message.
I want to send to the client eg. 404 eror
code with some message - how to do that? I tried many optiosn and I get always 400 BAD REQUEST
...
Or maybe I should do custom validation, eg go through some dto fields and in try catch check if storeId is number or not and then throw some error that will be catched in ExceptionHandler?
@Pattern(regexp = "[0-9]", message = "id must be a number")
doesn't work, I dont see any message that should be returned with the error