title: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type
body: <p>I have following controller method:</p>
  
  <pre><code>@RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST)
  public String saveTerminal( @RequestParam(value = "name") String name, 
                              @RequestParam(value = "file") @Valid OnlyForImagesFileWrapper file,
                                 BindingResult bindingResult )
               {
                  ...
  </code></pre>
  
  <p>and I see the following stacktrace:</p>
  
  <pre><code>    org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'com.terminal.domain.validation.OnlyForImagesFileWrapper'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.web.multipart.commons.CommonsMultipartFile] to required type [com.terminal.domain.validation.OnlyForImagesFileWrapper]: no matching editors or conversion strategy found
          at           org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:74)
          ....
          Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.web.multipart.commons.CommonsMultipartFile] to required type [com.terminal.domain.validation.OnlyForImagesFileWrapper]: no matching editors or conversion strategy found
              at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
              ... 71 more
  </code></pre>
  
  <p>OnlyForImagesFileWrapper source:</p>
  
  <pre><code>public class OnlyForImagesFileWrapper {
      @Extensions(imageFormats = {".jpg",".png",".gif",".bmp"}, videoFormats = {})
      private MultipartFile multipartFile;
      ...
  }
  </code></pre>
  
  <p>How to avoid the problem?</p>
  
  <p>Where can I set conversion politic for this controller method for multipart file?</p>
  
  <p><strong>P.S.</strong></p>
  
  <p>I tryed to write my custom initbinder:</p>
  
  <pre><code>@InitBinder
      public void initBinder(WebDataBinder binder) {
          binder.registerCustomEditor(CommonsMultipartFile.class, new PropertyEditorSupport() {
              @Override
              public void setValue(Object file) {
                  setValue(new OnlyForImagesFileWrapper((MultipartFile) file));
              }
          });
      }
  </code></pre>
  
  <p>But this method doesn't invoke when I submit form and I see stacktrace mentioned above.</p>
  
  <p><strong>P.S.</strong></p>
  
  <p>result after <strong>M. Deinum</strong> instruction execution(when I inside <code>saveTerminal</code> method):</p>
  
  <p><img src="https://i.stack.imgur.com/x9LEt.jpg" alt="http://dl2.joxi.net/drive/0005/3037/338909/150502/e592df25e4.jpg"></p>
  
  <p>Also I noticed that my initbinder method doesn't invoke.</p>
  
  <p>More details about my code(state after M. Denium advice):</p>
  
  <p>jsp:</p>
  
  <pre><code>&lt;input type="file" id="newFile" name="file" class="file" size="21.5" accept=".jpg,.png,.gif,.bmp" style="opacity: 0;"&gt;
  </code></pre>
  
  <p>arguments of controller method:</p>
  
  <pre><code>...
  @ModelAttribute @Valid OnlyForImagesFileWrapper wrapper,
                                 BindingResult bindingResult,
  ...
  </code></pre>