понеділок, 8 серпня 2011 р.

Jackson Pretty Printing

While playing with Jackson, I've found it's rather difficult to find a clue about how to provide visually attractive and human-readable JSON output.

Apparently it was rather simple to do, but not obvious. Here is the code (Colour is just an example POJO):

        Colour c = new Colour(22, 147, 165);
        ObjectMapper jsonMapper = new ObjectMapper();
              SerializationConfig.Feature.INDENT_OUTPUT, true);
        String dutchTeal = jsonMapper.writeValueAsString(c);

Немає коментарів:

Дописати коментар