users@jersey.java.net

Re: [Jersey] Re: Pretty print JSON output

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 6 Aug 2010 10:54:19 +0200

On Aug 6, 2010, at 7:34 AM, Tatu Saloranta wrote:

> On Thu, Aug 5, 2010 at 8:42 AM, Mike Baranczak
> <mbaranczak_at_gmail.com> wrote:
>>
>> Configuring JSON in Jersey is slightly convoluted, but it can be
>> done -
>> here's how:
>>
>> http://blogs.sun.com/japod/entry/configuring_json_for_restful_web
>>
>> I can't remember where the option for pretty-printing is, probably in
>> JSONConfiguration.
>
> FWIW, if using Jackson based JAX-RS provider, all you have to do is to
> configure ObjectMapper like so:
>
> objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT,
> true);
>

And it is also possible to configure "human readable formatting" for
Jersey's JAXB support [1]. But AFAIK it is not possible to configure
formating if using the low-level JSONArray and JSONObject types. But
perhaps you can better utilize Jackson Array/Map support rather than
JSONArray/JSONObject?

Paul.

[1] https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/json/JSONConfiguration.html
#createJSONConfigurationWithFormatted
%28com.sun.jersey.api.json.JSONConfiguration,%20boolean%29

> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>