Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Validator

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");
    }
}
like image 983
Kartik Goyal Avatar asked Feb 17 '26 20:02

Kartik Goyal


1 Answers

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

like image 84
Kislay Kishore Avatar answered Feb 19 '26 14:02

Kislay Kishore