List of utility methods to do XML JAXB String to Object
Object | convertStringToJAXB(String str) Converts a String object to a JAXB object.
Unmarshaller u = jaxbContext.createUnmarshaller(); return u.unmarshal(new StreamSource(new StringReader(str))); |
JAXBException | convertToJAXBException(String msg, Throwable e) Coverts the passed exception into a new instance of javax.xml.bind.JAXBException . return new JAXBException(msg, e); |
T | convertToObject(Class XML to Object return convertToObject(clazz, new InputStreamReader(inputStream)); |
void | convertToXmlFile(File file, Object source, Class>... type) convert To Xml File System.out.println("Generando Archivo: " + file.getName()); System.out.println("#############################"); try { JAXBContext jaxbContext = JAXBContext.newInstance(type); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(source, file); marshaller.marshal(source, System.out); ... |
Object | convertXmlFileToObject(Class> clazz, String xmlPath) convert Xml File To Object Object xmlObject = null; try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); FileReader fr = null; try { fr = new FileReader(xmlPath); } catch (FileNotFoundException e) { ... |
Object | convertXmlToObj(Class clazz, String xmlStr) convert Xml To Obj try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StringReader(xmlStr)); } catch (JAXBException e) { e.printStackTrace(); return null; ... |
T | convertXMLToObject(byte[] data, Class convert XML To Object javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(clazz.getPackage().getName()); Unmarshaller um = jaxbCtx.createUnmarshaller(); JAXBElement<T> element = (JAXBElement<T>) um.unmarshal(new ByteArrayInputStream(data)); return element.getValue(); |
T | converyToJavaBean(String xml, Class convery To Java Bean T t = null; try { JAXBContext context = JAXBContext.newInstance(c); Unmarshaller unmarshaller = context.createUnmarshaller(); t = (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { e.printStackTrace(); return t; |
T | converyToJavaBean(String xml, Class convery To Java Bean T t = null; try { JAXBContext context = JAXBContext.newInstance(c); Unmarshaller unmarshaller = context.createUnmarshaller(); t = (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { e.printStackTrace(); return t; |
T | converyToJavaBean(String xml, Class convery To Java Bean T t = (T) JAXB.unmarshal(new StringReader(xml), clazz); return t; |