Java Utililty Methods XML JAXB Unserialize

List of utility methods to do XML JAXB Unserialize

Description

The list of methods to do XML JAXB Unserialize are organized into topic(s).

Method

TloadXml(File file, Class requireType)
load Xml
JAXBContext context = JAXBContext.newInstance(requireType);
Unmarshaller um = context.createUnmarshaller();
return (T) um.unmarshal(file);
ObjectloadXML(Object object, String fileNamePath)
load XML
Unmarshaller unmarshaller = createUnmarshaller(object);
Object loaded = null;
File fileXML = createFile(fileNamePath);
if (fileXML.length() > 0) {
    try {
        loaded = unmarshaller.unmarshal(new FileReader(fileNamePath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
...
ObjectloadXMLFromString(Object object, String line)
load XML From String
Unmarshaller unmarshaller = createUnmarshaller(object);
Object loaded = null;
StringReader stringReader = new StringReader(line);
if (!line.isEmpty()) {
    try {
        loaded = unmarshaller.unmarshal(stringReader);
    } catch (JAXBException e) {
        e.printStackTrace();
...
Tparse(final Class clazz, final InputStream inputStream)
parse
try {
    final JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
    final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    final Object deserialized = jaxbUnmarshaller.unmarshal(inputStream);
    if (clazz.isAssignableFrom(deserialized.getClass())) {
        return clazz.cast(deserialized);
    } else {
        final JAXBElement<T> jaxbElement = (JAXBElement<T>) deserialized;
...
CalendarparseIsoDate(String lexicalDate)
Parses an ISO 8601 date string.
return javax.xml.bind.DatatypeConverter.parseDate(lexicalDate);
TparseJaxb(Class cls, InputStream in)
Parse XML using JAXB and a model class.
JAXBContext context = JAXBContext.newInstance(cls);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Unmarshaller um = context.createUnmarshaller();
return (T) um.unmarshal(in);
KparseXml(final Class klass, final Reader xmlReader)
parse Xml
JAXBContext context = JAXBContext.newInstance(klass);
return (K) context.createUnmarshaller().unmarshal(xmlReader);
TparseXML(String content, Class clazz)
parse XML
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(metadataSchema);
JAXBElement<T> unmarshalled = unmarshaller.unmarshal(new StreamSource(new StringReader(content)), clazz);
return unmarshalled.getValue();
TparseXmlFile(Class type, String filePath)
parse Xml File
T instance = null;
File file = new File(filePath);
JAXBContext jaxbContext = JAXBContext.newInstance(type);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
instance = (T) jaxbUnmarshaller.unmarshal(file);
return instance;
Tread(Class cl, InputStream is)
read
JAXBContext context = JAXBContext.newInstance(cl);
Unmarshaller unmarshaller = context.createUnmarshaller();
T o = cl.cast(unmarshaller.unmarshal(is));
return o;