title: How to send and receive JSON data from a restful webservice using Jersey API
body: <pre><code>@Path("/hello")
  public class Hello {
  
      @POST
      @Path("{id}")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public JSONObject sayPlainTextHello(@PathParam("id")JSONObject inputJsonObj) {
  
          String input = (String) inputJsonObj.get("input");
          String output="The input you sent is :"+input;
          JSONObject outputJsonObj = new JSONObject();
          outputJsonObj.put("output", output);
  
          return outputJsonObj;
      }
  } 
  </code></pre>
  
  <p>This is my webservice (I am using Jersey API). But I could not figure out a way to call this method from a java rest client to send and receive the json data. I tried the following way to write the client</p>
  
  <pre><code>ClientConfig config = new DefaultClientConfig();
  Client client = Client.create(config);
  WebResource service = client.resource(getBaseURI());
  JSONObject inputJsonObj = new JSONObject();
  inputJsonObj.put("input", "Value");
  System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).entity(inputJsonObj).post(JSONObject.class,JSONObject.class));
  </code></pre>
  
  <p>But this shows the following error </p>
  
  <pre><code>Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.Class, and MIME media type, application/octet-stream, was not found
  </code></pre>