title: HTTP 400 error in REST web service during POST with FormParam containing own objects (e.g. enities)
body: <p>For an ordering process in my REST service I have to send a list of "articles" from client to server. These article objects are of a self-made entity type. I already found out that sending a list of STRING or INTEGER objects does work, sending it via @FormParam.</p>
  
  <p>But as soon as I try to send a list of my own objects (even only ONE object), I always get a <strong>HTTP 400 error "Bad Request"</strong>.</p>
  
  <p>I tried excatly the same code like below (only the parameters of form.add() and the parameters of the server method were altered) and postet Strings, Integers and lists of Strings successfully. It only makes problems sending own object types.<br>
  Logging told me that the server method isn't reached. The process is broken somewhere before.</p>
  
  <p>I also tried to get the request by using a proxy (Apache JMeter). Here it says that the parameter <code>kunde</code> contains the value <code>entities.Kunde%40af8358</code>. So I guess the object is not serialized thoroughly (or at all). But sending this kind of object from server to client in a response works fine - here the XML-serialization is no problem.</p>
  
  <p>What might be the reason? Is it maybe NOT possible to send own types through POST?<br>
  (PS: The type <code>Kunde</code>in my example is serializable and annotated with <code>@XmlRootElement</code>.)</p>
  
  <p>Thank you in advance for your help!<br>
  Jana</p>
  
  <p><strong>Note</strong>: I'm using the SAP Netweaver AS. But until now it behaved like every other Java AS, so I don't think this will be the reason. Every other REST operation does work, even POST without own entities.</p>
  
  <p><strong>Addition</strong>: I'm using the JERSEY library.</p>
  
  <hr>
  
  <p>My Code on server side:</p>
  
  <pre><code>@Path("/test")
      @POST
      @Produces(MediaType.TEXT_XML)
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)    
      public String test(
          @FormParam("kunde") Kunde kunde) {    
  
          return "The name of the customer is: "
             +kunde.getVorname()+" "+kunde.getNachname();        
      }
  </code></pre>
  
  <p>My code on client side (the method is in a Session Bean):</p>
  
  <pre><code>public String  test() {
  
      Kunde kunde = new Kunde();
      kunde.setNachname("Müller");
      kunde.setVorname("Kurt");
  
      Form form = new Form();
      form.add("kunde", kunde);       
  
      return service
          .path("test")
          .type(MediaType.APPLICATION_FORM_URLENCODED)
          .accept(MediaType.TEXT_XML)
          .post(String.class, form);
  }
  </code></pre>
  
  <p>where <strong>service</strong> is built like that:</p>
  
  <pre><code>com.sun.jersey.api.client.Client;
  com.sun.jersey.api.client.WebResource;
  com.sun.jersey.api.client.config.ClientConfig;
  com.sun.jersey.api.client.config.DefaultClientConfig;
  
  ClientConfig config = new DefaultClientConfig();
  Client client = Client.create(config);
  service = client.resource(UriBuilder.fromUri("&lt;service-url&gt;").build());
  </code></pre>