List of utility methods to do XML JAXB Serialize
T | deserialize(Class deserialize File file = new File(filename); JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); T t = (T) jaxbUnmarshaller.unmarshal(file); return t; |
T | deSerialize(Class Deserialize the XML content of a stream into a Java object of the specified type. return deSerialize(docClass, new StreamSource(inputStream)); |
Object | deserialize(Element elmnt, Class cls) deserialize final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller(); return um.unmarshal(elmnt); |
Object | deserialize(File fXMLFilePath, Class cls) deserialize final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller(); return um.unmarshal(fXMLFilePath); |
Object | deserialize(final Class clazz, final String json) deserialize ObjectMapper mapper = new ObjectMapper(); Object object = mapper.readValue(json, clazz); return object; |
T | deserialize(Path input, Class deserialize InputStream in = new FileInputStream(input.toFile()); return deserialize(in, clazz); |
Object | deserialize(String data, String className) deserialize if (className == null || className.length() == 0) return null; if (data != null && data.length() > 0) { try (StringReader reader = new StringReader(data)) { try { JAXBContext ctx = JAXBContext.newInstance(Class.forName(className)); Unmarshaller um = ctx.createUnmarshaller(); return um.unmarshal(reader); ... |
T | deserializeFile(String path, Class Reads a file and deserializes it to an object of given class. try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller m = context.createUnmarshaller(); Object o = m.unmarshal(new FileInputStream(path)); return clazz.cast(o); } catch (JAXBException e) { e.printStackTrace(); } catch (FileNotFoundException e) { ... |
T | deserializeFromXmlFile(T defaultObject, String fileName) deserialize From Xml File T object = defaultObject; try { JAXBContext context = JAXBContext.newInstance(defaultObject.getClass()); try (FileInputStream inStream = new FileInputStream(fileName)) { object = (T) context.createUnmarshaller().unmarshal(inStream); } catch (JAXBException | IOException e) { return object; |
Serializable | deserializeXmlToJava(String valueType, Serializable value) deserialize Xml To Java Serializable deserializedValue = null; if (value != null) { XMLStreamReader xml = null; if (value instanceof String) { xml = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader((String) value)); if (xml != null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); ... |