title: Sending Json [Gson implementation] from Rest-Webservice
body: <p>I am using Gson library to handle parsing Json to java entities and vice-versa.
  Now, after processing the in need to return the Json object to the caller.
  But doing so results in following exception:</p>
  
  <pre><code>Mar 25, 2014 4:46:30 PM com.sun.jersey.spi.container.ContainerResponse write
  SEVERE: A message body writer for Java class com.google.gson.JsonObject, and Java type class com.google.gson.JsonObject, and MIME media type application/json was not found
  Mar 25, 2014 4:46:30 PM com.sun.jersey.spi.container.ContainerResponse write
  SEVERE: The registered message body writers compatible with the MIME media type are:
  </code></pre>
  
  <p>Json after processing is <code>{"status":"Entity added successfully."}</code></p>
  
  <p><strong>My Observation</strong>: It seems like i need to register <code>Gson</code> implementation for Json somewhere to let the container know that I will send Json data using Gson's JsonObject. If i observed correctly, then where should i register and how, or if i am totally wrong then, please correct me.</p>
  
  <p>My implementation looks like following:</p>
  
  <pre><code>@POST
  @Path("/entity")
  @Produces(MediaType.APPLICATION_JSON)
  public Response addEntity(@FormParam("entity") String jsonEntity, @FormParam("entityType") String jsonEntityType) {
      JsonObject jSonStatus = null;
      log.info("Entered webservice method: " + jsonEntity.toString() + "\n" + jsonEntityType.toString());
      if (jsonEntity != null &amp;&amp; jsonEntityType != null) {
          dispatcher = dispatcher.getDispatcher();
          jSonStatus = dispatcher.addEntity(jsonEntity, jsonEntityType);
      }
      log.info("Returning from webservice method: " + jSonStatus);
      ResponseBuilder rb = new ResponseBuilderImpl();
      // rb.type(MediaType.APPLICATION_JSON);   tried with this also, but no luck
      rb.entity(jSonStatus);
      rb.status(Status.OK);
  
      return rb.build();
  }
  </code></pre>