title: How should I return JSON response in Jersey 2
body: <p>I'm facing issue while trying to return Response with JSON object in Jersey 2.</p>
  
  <p>Following is the code snippet:</p>
  
  <pre><code>        import javax.ws.rs.GET;
          import javax.ws.rs.Path;
          import javax.ws.rs.Produces;
          import javax.ws.rs.core.MediaType;
          import javax.ws.rs.core.Response;
          import javax.ws.rs.core.Response.Status;
          import org.codehaus.jettison.json.JSONObject;
  
          @Path("/message")
          public class HelloWorld {
  
            @Path("/getJson")
            @GET
            @Produces(MediaType.APPLICATION_JSON)
            public Response getJSON() {
              JSONObject object = null;
              Response response = null;
              try {
                object = new JSONObject();
                object.put("Name", "Bryan");
                object.put("Age", "27");
                response = Response.status(Status.OK).entity(object).build();
              } catch (Exception e) {
                System.out.println("error=" + e.getMessage());
              }
              return response;
            }
          }
  </code></pre>
  
  <p>I'm getting the below exception:</p>
  
  <pre><code> No serializer found for class org.codehaus.jettison.json.JSONObject and no  properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
  </code></pre>
  
  <p>Related posts advised me to try the following.</p>
  
  <ol>
  <li><p>Use ObjectMapper and set the property 
  <strong>mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);</strong> : I don't need to use ObjectMapper in this scenario as I just want to return a json object. </p></li>
  <li><p>Try POJO instead of JSON Object:
  Yes POJO works fine but that is not what I wanted. I need to return the Response with Json object which will be parsed by my Java script code.</p></li>
  </ol>