@Test public void testToJson() { MSString obj = new MSString("testing 123"); String expectedJson = "{\"value\":\"testing 123\"}"; String json = dtoUtil.toJSON(obj); assertThat(json).isEqualTo(expectedJson); }
public String toJSON(Object obj) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(obj); } catch (IOException e) { LOG.error("toJSON failed", e); return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); } }
DTOUtil { public String toJSON(Object obj) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(obj); } catch (IOException e) { LOG.error("toJSON failed", e); return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); } } }
DTOUtil { public String toJSON(Object obj) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(obj); } catch (IOException e) { LOG.error("toJSON failed", e); return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); } }  }
DTOUtil { public String toJSON(Object obj) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(obj); } catch (IOException e) { LOG.error("toJSON failed", e); return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); } }  @SuppressWarnings({ "unchecked", "known.nonnull" }) String toXML(@Nonnull T obj); T toObject(String xml, Class<T> clazz); String toJSON(Object obj); static T fromJSONToObject(String json, Class<T> clazz); }
DTOUtil { public String toJSON(Object obj) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(obj); } catch (IOException e) { LOG.error("toJSON failed", e); return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); } }  @SuppressWarnings({ "unchecked", "known.nonnull" }) String toXML(@Nonnull T obj); T toObject(String xml, Class<T> clazz); String toJSON(Object obj); static T fromJSONToObject(String json, Class<T> clazz);  }