title: How do I POST a Pojo with Jersey Client without manually convert to JSON?
body: <p>I have a working json service which looks like this:</p>
  
  <pre><code>@POST
  @Path("/{id}/query")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(JSON)
  public ListWrapper query(@Context SecurityContext sc, @PathParam("id") Integer projectId, Query searchQuery) {
      ...
      return result
  }
  </code></pre>
  
  <p>The query object looks like this and when posting a json representation of that Query object it works out nice. </p>
  
  <pre><code>@XmlRootElement
  public class Query {
      Integer id;
      String query;
      ... // Getters and Setters etc..
  }
  </code></pre>
  
  <p>Now I want to fill that object from a client and use Jersey client to post that Query object to the service and get an JSONObject as a result. My understanding is that it could be done without converting it to a json object first and then posted as a String.</p>
  
  <p>I have tried something like this but I think I miss something.</p>
  
  <pre><code>public static JSONObject query(Query searchQuery){
      String url = baseUrl + "project/"+searchQuery.getProjectId() +"/query";
      WebResource webResource = client.resource(url);
      webResource.entity(searchQuery, MediaType.APPLICATION_JSON_TYPE);
      JSONObject response = webResource.post(JSONObject.class);
      return response;
  }
  </code></pre>
  
  <p>I'm using Jersey 1.12.</p>
  
  <p>Any help or pointer in the right direction would be much appreciated.</p>