List of utility methods to do XML JAXB String to Object
T | fromXml(InputStream input, Class from Xml try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new InputStreamReader(input, CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); ... |
T | fromXml(InputStream xml, Class Deserialize the XML InputStream into an instance of provided class JAXBContext context = JAXBContext.newInstance(objectClass);
T obj = (T) context.createUnmarshaller().unmarshal(xml);
return obj;
|
T | fromXml(Reader xml, Class Converts an input XML reader into the given type. JAXBContext context = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (T) unmarshaller.unmarshal(xml);
|
T | fromXml(String responseBody, Class from Xml ByteArrayInputStream inputStream = new ByteArrayInputStream(responseBody.getBytes()); JAXBContext jaxbContext = JAXBContext.newInstance(c); XMLStreamReader xsr = xmlInputFactory.createXMLStreamReader(inputStream); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); return (T) jaxbUnmarshaller.unmarshal(xsr); |
T | fromXml(String xml, Class from Xml try { StringReader reader = new StringReader(xml); return (T) createUnmarshaller(clazz).unmarshal(reader); } catch (JAXBException e) { throw new RuntimeException(e); |
T | fromXml(String xml, Class from Xml try { return (T) JAXBContext.newInstance(type).createUnmarshaller() .unmarshal(new ByteArrayInputStream(xml.getBytes())); } catch (JAXBException e) { throw new RuntimeException(e); |
T | fromXML(String xml, Class from XML try { JAXBContext context = JAXBContext.newInstance(valueType); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { throw new RuntimeException(e.getMessage()); |
Object | getXmlObject(String xml, Class cls) get XML object for the xml string. return JAXB.unmarshal(new StringReader(xml), cls); |
Object | stringToObject(String s, Class theclass) string To Object Object o = null; ByteArrayInputStream input = new ByteArrayInputStream(s.getBytes()); JAXBContext jaxbContext = JAXBContext.newInstance(theclass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); o = theclass.cast(jaxbUnmarshaller.unmarshal(input)); return o; |
Object | toObject(Class className, String strXml) to Object Object object = null; StringReader reader = null; try { reader = new StringReader(strXml); JAXBContext context = JAXBContext.newInstance(className); Unmarshaller unmarshaller = context.createUnmarshaller(); object = unmarshaller.unmarshal(reader); } catch (Exception e) { ... |