List of utility methods to do XML JAXB String to Object
T | toObject(String xml, Class to Object if (xml == null || "".equals(xml.trim())) { return null; StringReader reader = null; try { JAXBContext context = JAXBContext.newInstance(c); javax.xml.bind.Unmarshaller unmarshaller = context.createUnmarshaller(); reader = new StringReader(xml); ... |
T | toObject(String xml, Class to Object 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(); |
Object | xml2obj(final Class> cls, final String xml) xmlobj StringReader reader = new StringReader(xml); JAXBContext contextIn = JAXBContext.newInstance(cls); Unmarshaller marshallerIn = contextIn.createUnmarshaller(); return marshallerIn.unmarshal(reader); |
T | xml2Object(String content, Class xml Object try { JAXBContext jaxbContext = JAXBContext.newInstance(valueType); Unmarshaller um = jaxbContext.createUnmarshaller(); T t = (T) um.unmarshal(new ByteArrayInputStream(content.getBytes())); return t; } catch (JAXBException e) { return null; ... |
Object | Xml2Object(String xmlString, Class> clazz) Xml Object if (xmlString == null || "".equals(xmlString.trim())) { return null; Unmarshaller unmarshaller = createUnMarshallerByClazz(clazz); return unmarshaller.unmarshal(new StringReader(xmlString)); |
T | xmlToJavaBean(String xml, Class xml To Java Bean if (xml.trim().isEmpty()) { return null; T t = null; try { JAXBContext context = JAXBContext.newInstance(c); Unmarshaller unmarshaller = context.createUnmarshaller(); t = (T) unmarshaller.unmarshal(new StringReader(xml)); ... |
JAXBElement> | xmlToJaxb(Class> xmlClass, String xml) xml To Jaxb JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<?> element; try (StringReader reader = new StringReader(xml)) { element = (JAXBElement<?>) unmarshaller.unmarshal(reader); return element; |
Object | xmlToJaxb(Class> xmlClass, String xml) xml To Jaxb JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<?> element; try (StringReader reader = new StringReader(xml)) { element = (JAXBElement<?>) unmarshaller.unmarshal(reader); return element.getValue(); |
Object | xmlToObject(String xml, Class>... type) xml To Object try { JAXBContext jaxbContext = JAXBContext.newInstance(type); StringReader stringReader = new StringReader(xml); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); return jaxbUnmarshaller.unmarshal(stringReader); } catch (JAXBException e) { e.printStackTrace(); return null; |
T | xmlToObject(String xml, Class Transforma o String do XML em Objeto JAXBContext context = JAXBContext.newInstance(classe); Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(new StringReader(xml)), classe).getValue(); |