1

I have big controller with different methods. I implement custom validator using org.springframework.validation

Hove to 'disable' validation for some controller methods? Or choose method - validator map.

For now - validation applied for all methods. And error:

Invalid target for Validator

Methods with validation:

@RequestMapping( value = "/" + API_METHOD_NAME_LIST_PLAYERS, method = RequestMethod.POST )
  public CResponseEntityWithView< CDefaultResponseBody< ?, ? > > listPlayers( CRequestList request ) {

@RequestMapping( value = "/" + API_METHOD_NAME_UPDATE, method = RequestMethod.POST )
  public CResponseEntityWithView< CDefaultResponseBody< ?, ? > > updatePlayer( @Valid @RequestBody CRequestUpdate request )

For last - I've added validator:

@InitBinder
private void initBinder(WebDataBinder binder) {
    binder.setValidator(validator);
}

I no need to validate both requests. Only second.

yazabara
  • 1,253
  • 4
  • 21
  • 39

2 Answers2

2

Assuming you are using annotations you can:

  1. Skip off the @Valid annotation where not needed.
  2. Define multiple validators if appropriate. See here
Community
  • 1
  • 1
user1675642
  • 747
  • 2
  • 5
  • 15
0

Could you post an example of controller method, because in order to suggest something more details would be nice. And saying that you are using particular package doesn't say much (tons of ways you can use it).

If you need to apply particular validations for objects passed as controller method arguments, I would suggest you to look into @ValidationGroup.

Vilius
  • 77
  • 3