JacksonObjectMapper { public byte[] toPrettyJson(Object object, Class<?> serializationView) throws IOException { return objectMapper.writerWithView(serializationView) .with(new DefaultPrettyPrinter() .withArrayIndenter(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE)) .writeValueAsString(object) .getBytes(StandardCharsets.UTF_8); } JacksonObjectMapper(ObjectMapper objectMapper); T fromJson(byte[] bytes, Class<T> type); T fromJson(byte[] bytes, Class<T> type, Class<?> view); Map<String, String> fromJsonToMap(byte[] bytes); byte[] toJson(Object object); byte[] toJson(Object object, Class<?> serializationView); byte[] toJson(Map<String, String> map); byte[] toPrettyJson(Object object, Class<?> serializationView); String prettyPrint(Object object); String prettyPrint(String json); void checkValidJson(byte[] bytes); T assign(T target, byte[] source);  }
@Test public void should_serialize_object_into_human_readable_json_using_serialization_view() throws Exception { SimpleObject object = new SimpleObject("id", "Vincent", 1); assertThat(new String(objectMapper.toPrettyJson(object, JsonViewPersistence.class))).isEqualTo("{" + System.lineSeparator() + " \"name\" : \"Vincent\"," + System.lineSeparator() + " \"number\" : 1" + System.lineSeparator() + "}"); }