I'm using a Jersey (v 1.17.1) client to communicate with a remote server that I don't have under my control (so I can't see the incomming requests).
I like to issue a POST request with JSON data, that has a structure similar to this example:
{"customer":"Someone",
 "date":"2013-09-12",
 "items":[{
     "sequenceNo":1,
     "name":"foo",
     "quantity":2,
     "price":42,
     "tax":{"percent":7,"name":"vat 7%"}
   },
   {
     "sequenceNo":2,
     "name":"bar",
     "quantity":5,
     "price":23,
    "tax":{"percent":7,"name":"vat 7%"}
   }
 ]
}
That's my code:
final Client c = Client.create();
final WebResource service = c.resource(SERVER);
final Form form = new Form();
form.add("customer", "Someone");
form.add("date", "2013-09-12");
form.add("items", XXX); // how do I do that?
final ClientResponse response = service.path("aPath").queryParam("param", "value").cookie(new Cookie("token", token))
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, form);
    final String raw = response.getEntity(String.class);
    System.out.println("Response " + raw);
I tried several approaches (like nesting another Form object), but I always get the same result: The server returns 400 - Bad Request ("The request sent by the client was syntactically incorrect (Bad Request).") I assume because the mandatory parameter items isn't sent correctly.
Does somebody know how I nest JSON data like described? I think it is a common case, but I found no examples in the web.