Is there any way through which I can validate function parameters of type String using @Valid annotation ?
I have been trying to do that but not able to do so. Here is my code:-
@Controller public class GameController { @Autowired private HeaderValidator headerValidator; @InitBinder private void initBinder(WebDataBinder binder) { binder.setValidator(new CompoundValidator(headerValidator)); } @RequestMapping(value = "game", method = RequestMethod.GET) public @ResponseBody Game getGame( @Valid @RequestHeader(value = "header", required = true) String header) { return new Game(1, "Baddy"); } }
@Validworks for model attributes not for header values. You would have to do manual validation for that.