title: Supporting both Multipart and Application Url Encoded parameters in Jersey
body: <p>I have a rest service in Jersey. I would like to have some post method that accepts parameters both as multipart and as url encoded. I started with : </p>
  
  <pre><code>@POST
  @Path("/some/resource")
  public String addSomeResource(@FormParam("param") String param) {
       repository.add(new SomeResource(param));
  }
  </code></pre>
  
  <p>My understanding is that using @Consumes more narrowly defines what's acceptable, and sure enough, this method is called whether someone attaches form data the usual way </p>
  
  <pre><code>$.ajax({url:'/some/resource', type:'POST', data:'&amp;param=foo'});
  </code></pre>
  
  <p>or via a multipart form submission (from some Java client wrapping http client).</p>
  
  <p>But when it comes in via multipart - the mapping doesn't happen and <code>param</code> is null. I am assuming that that is because it is expecting a <code>@FormDataParam</code> and not a <code>@FormParam</code> in the method - but I also believe that I can only use <code>@FormDataParam</code> when I've more narrowly defined the Consumes as Multipart-only. The documentation for <code>FormDataParam</code> (<a href="http://jersey.java.net/nonav/apidocs/1.5/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html" rel="noreferrer">http://jersey.java.net/nonav/apidocs/1.5/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html</a>) seems to imply that <code>FormDataParam</code> can fall back on <code>FormData</code> if no multipart parameter is there.</p>
  
  <p>My current solution to this is to have two methods for each post option: </p>
  
  <pre><code>@POST
  @Path("/some/resource")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public String addSomeResource(@FormParam("param") String param) {
       repository.add(new SomeResource(param));
  }
  @POST
  @Path("/some/resource")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public String addSomeResourceMP(@FormDataParam("param") String param) {
       return addSomeResource(param);
  }
  </code></pre>
  
  <p>Which seems like it might work, but I wonder if I'm just misunderstanding something more fundamental here, or missing a different fix that is a little better.</p>