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");
}
}
Since I don't have enough reputation to add my comments....writing here. In addition to what @M.Deinum commented,there is open JIRA for the same, and I guess the fix is expected in 4.3.
https://jira.spring.io/si/jira.issueviews:issue-html/SPR-6380/SPR-6380.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With