List of utility methods to do XML JAXB Unserialize
T | read(File file, Class Reads an XML file and returns the content as an object of the specified class. T content = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(typeParameterClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); content = (T) jaxbUnmarshaller.unmarshal(file); } catch (JAXBException e) { e.printStackTrace(); return content; |
String | readComplexProperty(String name, List read Complex Property for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart())) { return callMethod(element.getValue(), methodName); return null; |
Object | readExternal(InputStream inputStream, Class> clazz) Reads the InputStream of JAXB marshaled xml and creates an object of the given Class Object object = null; try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); object = (Object) unmarshaller.unmarshal(inputStream); } catch (Exception e) { e.printStackTrace(); return object; |
T | readJAXB(Class read JAXB JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller u = jc.createUnmarshaller();
return (T) u.unmarshal(is);
|
T | readJaxbObject(InputStream inputStream, Class read Jaxb Object JAXBContext context = JAXBContext.newInstance(jaxbModelClass.getPackage().getName()); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setEventHandler(new DefaultValidationEventHandler()); return unmarshaller.unmarshal(new StreamSource(inputStream), jaxbModelClass).getValue(); |
T | readObject(Class read Object JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (T) unmarshaller.unmarshal(file);
|
T | readObjectFromInputStream(final InputStream inputStream, final Class read Object From Input Stream try { JAXBContext jaxbContext = JAXBContext.newInstance(expectedType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<T> element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType); return element.getValue(); } catch (final JAXBException e) { throw new RuntimeException("Cannot process resource!", e); |
T | readObjectFromXml(Class read java object from XML. InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFileName);
return readObjectFromXml(jaxbBindClass, is);
|
JAXBElement> | readXmlFileToObj(String path, String packageName) read Xml File To Obj File file = new File(path); JAXBContext jContext = JAXBContext.newInstance(packageName); Unmarshaller unmarshaller = jContext.createUnmarshaller(); return (JAXBElement<?>) unmarshaller.unmarshal(file); |
String | unserialize(T component, Class unserialize try { Marshaller marshaller = JAXBCONTEXT.createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(component, sw); return sw.toString(); } catch (JAXBException je) { return "failed"; |