List of utility methods to do XML JAXB String to Object
Object | createObject(String xml, Object type) create Object JAXBContext jc = JAXBContext.newInstance(type.getClass()); Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8")); Object obcj = unmarshaller.unmarshal(stream); return obcj; |
Object | fromFile(Class jaxbClass, String fileName) fromFile retrieves object of given class from given file (in classpath) JAXBContext context = JAXBContext.newInstance(jaxbClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(null);
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
InputStream is = tccl.getResourceAsStream(fileName);
return fromStream(jaxbClass, is);
|
Object | fromStream(Class jaxbClass, InputStream is) fromStream retrieves object of given class from given inputstream JAXBContext context = JAXBContext.newInstance(jaxbClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(null);
return jaxbClass.cast(unmarshaller.unmarshal(is));
|
T | fromStringToObject(String xmlString, Class from String To Object return JAXB.unmarshal(new StringReader(xmlString), xmlObjClass); |
Object | fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml) from Xml JAXBContext context = null; try { context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(new StringReader(stringXml))); } catch (JAXBException e) { e.printStackTrace(); return null; |
T | fromXML(Class from XML JAXBContext context = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (T) unmarshaller.unmarshal(is);
|
T | fromXml(Class from Xml JAXBContext jaxbContext = null; try { jaxbContext = JAXBContext.newInstance(tClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); return (T) jaxbUnmarshaller.unmarshal(inputStream); } catch (JAXBException e) { e.printStackTrace(); return null; ... |
T | fromXml(File xmlPath, Class from Xml BufferedReader reader = null; StringBuilder sb = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(xmlPath), ENCODING)); String line = null; sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); ... |
Object | fromXML(final byte[] data, final Class> type) Converts byte data representing XML of a JAXB object to an object. try { final JAXBContext context = getContext(type); final Unmarshaller unMarshal = context.createUnmarshaller(); final JAXBElement<?> temp = unMarshal.unmarshal(new StreamSource(new ByteArrayInputStream(data)), type); return temp.getValue(); } catch (final JAXBException exception) { throw new IllegalStateException(exception); |
T | fromXml(final Reader reader, final Class from Xml Unmarshaller un = null; try { un = getJaxbContext(dtoClass).createUnmarshaller(); return (T) un.unmarshal(reader); } catch (JAXBException e) { throw new RuntimeException(e); |