List of utility methods to do XML JAXB Unserialize
T | inputStreamToObject(InputStream xml, Class input Stream To Object JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); try { return (T) unmarshaller.unmarshal(xml); } finally { xml.close(); |
T | inputStreamToObject(String xml, Class input Stream To Object InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); JAXBContext jaxbContext = JAXBContext.newInstance(classes); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); T unmarshal = (T) unmarshaller.unmarshal(stream); return unmarshal; |
E | load(Class load JAXBContext jaxbContext; Unmarshaller jaxbUnmarshaller; jaxbContext = JAXBContext.newInstance(clazz); jaxbUnmarshaller = jaxbContext.createUnmarshaller(); @SuppressWarnings("unchecked") E result = (E) jaxbUnmarshaller.unmarshal(is); return result; |
E | load(Class load JAXBContext jaxbContext; Unmarshaller jaxbUnmarshaller; jaxbContext = JAXBContext.newInstance(clazz); jaxbUnmarshaller = jaxbContext.createUnmarshaller(); @SuppressWarnings("unchecked") E result = (E) jaxbUnmarshaller.unmarshal(is); return result; |
T | load(File f, Class... args) load return load(new FileInputStream(f), args); |
T | load(final String xml, final Class load StringReader reader = new StringReader(xml); try { final JAXBContext context = JAXBContext.newInstance(clazz); final Unmarshaller um = context.createUnmarshaller(); @SuppressWarnings("unchecked") final T resource = (T) um.unmarshal(reader); return resource; finally { reader.close(); |
T | load(InputStream input, Class load try { JAXBContext context = JAXBContext.newInstance(type); Unmarshaller um = context.createUnmarshaller(); return (T) um.unmarshal(input); } catch (JAXBException ex) { throw new IOException("Exception thrown while deserializing stream", ex); |
T | loadObject(Class load Object T object = null; try { File file = new File(path.toURI()); JAXBContext jaxbContext = JAXBContext.newInstance(typeClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); object = (T) jaxbUnmarshaller.unmarshal(file); } catch (JAXBException e) { e.printStackTrace(); ... |
T | loadObject(Path path, Class Loads the object from the file. T result; if (path == null || clazz == null) { throw new RuntimeException("The path to file or class is null!"); try { JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); result = (T) jaxbUnmarshaller.unmarshal(path.toFile()); ... |
T | loadXML(Class load XML try { JAXBContext context = JAXBContext.newInstance(type); return (T) context.createUnmarshaller().unmarshal(sourceFile); } catch (JAXBException e) { throw new RuntimeException(e); |