@Test public void testToObject() throws JAXBException { String xml = "<MSString>testing 123</MSString>"; MSString expectedObj = new MSString("testing 123"); MSString obj = dtoUtil.toObject(xml, MSString.class); assertThat(obj).isEqualTo(expectedObj); }
public <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); }
DTOUtil { public <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); } }
DTOUtil { public <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); }  }
DTOUtil { public <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); }  @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 <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); }  @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);  }