I want to automatically validate REST
parameters on a spring REST
service.
I tried it using @Valid @NotNull
, but the rest request does not get rejected automatically, but the dao method is executed with null argument. Why?
@RestController
public class RestController {
@RequestMapping(value = "/")
public Boolean getResponse(@Valid @NotNull @Length(max = 20) String username) {
return daoService.lookup(username); //is executed if username = null
}
}
How can I get automatically a returned HTTP error, eg 400?