title: Spring MVC customized method parameter binding
body: <p>I'm looking for a way to customize the default Spring MVC parameter binding. Take this method as an example:</p>
  
  <pre><code>@RequestMapping(value="/index.html")
  public ModelAndView doIndex(@RequestParam String param) {
    ...
  </code></pre>
  
  <p>This is easy, when I have just a <code>String</code>that I want to extract from the request. However, I want to populate a more complete object, so that my method looks like this:</p>
  
  <pre><code>@RequestMapping(value="/index.html")
  public ModelAndView doIndex(Foo bar) {
    ...
  </code></pre>
  
  <p>What I'm looking for is some way to declare a binding like this;</p>
  
  <pre><code>@RequestMapping(value="/index.html")
  public ModelAndView doIndex(@FooPopulator Foo bar) {
    ...
  </code></pre>
  
  <p>And have some other kind of implementor (determined by the <code>@FooPopulator</code> annotation) that does this:</p>
  
  <pre><code>public void doBind(Foo target, ServletRequest originalRequest) {
    target.setX(this.computeStuffBasedOn(originalRequest));
    target.sety(y);
  }
  </code></pre>
  
  <p>So far I've found out about the <code>@InitBinder</code>binder annotaion but I'm unsure whether that's really the right choice for this scenarion.</p>
  
  <p>What's the best way?</p>