Annotation to modify a request parameter
<p>How to modify a request parameter (<code>@RequestParam String bar</code>) before entering in the controller ?</p>

<p>Ideally I'd like to create an annotation :
</p>

<pre class="lang-java prettyprint-override"><code>@RequestMapping(method = GET, path = "foo")
public ResponseEntity&lt;String&gt; getBar(@RequestParam @Sanitize("bar") String bar) {

    // bar is sanitized

    /** method body *//
}
</code></pre>

<p>According <a href="https://stackoverflow.com/questions/30715579/custom-spring-annotation-for-request-parameters">to this question</a>, I tried to create the interface <code>Sanitize</code>:</p>

<pre class="lang-java prettyprint-override"><code>@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Sanitize {
    String value();
}
</code></pre>

<p>And a resolver <code>SanitizeResolver</code></p>

<pre class="lang-java prettyprint-override"><code>public class SanitizeResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterAnnotation(Sanitize.class) != null;
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                                  NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        Sanitize attr = parameter.getParameterAnnotation(Sanitize.class);
        return MyUtils.sanitize(webRequest.getParameter(attr.value()));
    }
}
</code></pre>

<p>And to add the resolver to my <code>WebMvcConfigurerAdapter</code>'s resolver:</p>

<pre class="lang-java prettyprint-override"><code>@Override
public void addArgumentResolvers(List&lt;HandlerMethodArgumentResolver&gt; argumentResolvers) {
    argumentResolvers.add(new SanitizeResolver());
}
</code></pre>

<p>The resolver is well added but never called.</p>

<p>I'm using <a href="http://docs.spring.io/spring/docs/4.2.6.RELEASE/spring-framework-reference/htmlsingle/" rel="nofollow noreferrer">Spring 4.2.6.RELEASE</a>.
Do I miss something, and if can't work, is there a better solution ?</p>