JacksonObjectMapper { public byte[] toJson(Object object) throws IOException { return objectMapper.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_json() throws Exception { SimpleObject object = new SimpleObject("id", "Vincent", 1); JSONAssert.assertEquals(new String(objectMapper.toJson(object)), "{\"name\":\"Vincent\",\"number\":1, \"another\": null, \"id\": \"id\"}", false); }
@Test public void should_serialize_map_into_json() throws Exception { Map<String, String> map = new HashMap<>(); map.put("name", "walter"); map.put("lastname", "bates"); JSONAssert.assertEquals(new String(objectMapper.toJson(map)), "{\"name\":\"walter\",\"lastname\":\"bates\"}", false); }
@Test public void should_serialize_object_into_json_using_serialization_view() throws Exception { SimpleObject object = new SimpleObject("id", "Vincent", 1); JSONAssert.assertEquals(new String(objectMapper.toJson(object, JsonViewPersistence.class)), "{\"name\":\"Vincent\",\"number\":1}", false); }