I have a working json service that looks like this:
@POST @Path("/{id}/query") @Consumes(MediaType.APPLICATION_JSON) @Produces(JSON) public ListWrapper query(@Context SecurityContext sc, @PathParam("id") Integer projectId, Query searchQuery) { ... return result }
The query object looks like this, and when publishing the json representation of this Query object, it works well.
@XmlRootElement public class Query { Integer id; String query; ...
Now I want to fill this object with the client and use the Jersey client to send this Query object to the service and get a JSONObject as a result. I understand that this can be done without first converting it to a json object, and then sending it as a string.
I tried something like this, but I think I missed something.
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; }
I am using Jersey 1.12.
Any help or pointer in the right direction would be greatly appreciated.
java json jackson jersey client
Perty
source share