Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have a bit of a round about solution that prints it pretty decently. (Not the best Pretty Print but it is enough)</p> <p>You'll need the following from Maven:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt; &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt; &lt;version&gt;1.9.13&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Then you can change your method to something like this:</p> <pre><code>import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectWriter; ... private final ObjectWriter WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter(); ... @GET @Path("books") @Produces({ MediaType.APPLICATION_JSON }) public Response getBooks() { return Response.status(Status.OK).entity(WRITER.writeValueAsString(doGetBooks())).build(); } </code></pre> <p>Since what it does is:</p> <ol> <li>Converts your Objects to a Pretty JSON String</li> <li>Returns a <code>Response</code> object with a <code>200</code> Response Code with the <code>JSON String</code>.</li> </ol> <p>Edit: it might be wise to make this available by a adding a query param like <code>pretty=true</code> since it would increase your response output size. </p> <p>You can also look at this: <a href="http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/Built_in_JAXB_providers.html#decorators" rel="nofollow">http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/Built_in_JAXB_providers.html#decorators</a> which describes creating a XML decorator which you may be able to adapt for JSON to still return objects and make it behind the scenes. (I'll try to fiddle with this later)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload