Hi All…
I wish to use bean validation annotations on parameters of methods of a custom @RestController … it seems like this should be supported when controller method marked @Validated, but it is not working… is this to be expected?
resttest.zip (419.3 KB)
Attached is sample project with a sum method with min/max constraints on first parameter.
When service called via restapi addon, constraint is enforced:
@Validated public Integer sum(@Min(4) @Max(10) Integer number1, Integer number2) { return number1+number2; }
http://localhost:8080/app/rest/v2/services/resttest_TestService/sum?number1=17&number2=34
{
“message”: “must be less than or equal to 10”,
“messageTemplate”: “{javax.validation.constraints.Max.message}”,
“path”: “sum.arg0”,
“invalidValue”: 17
}
but when custom controller method with same constraint called, it is not caught:
public class MyController {
@GetMapping("/func") @Validated public Integer sum(@Min(4) @Max(10) Integer number1, Integer number2) { return number1+number2; }
}
http://localhost:8080/app/rest/myapi/func?number1=17&number2=3
20
Is there some straightforward way to get validation on the custom controller?