Java Utililty Methods XML JAXB Serialize

List of utility methods to do XML JAXB Serialize

Description

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

Method

Tdeserialize(Class clazz, String filename)
deserialize
File file = new File(filename);
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
T t = (T) jaxbUnmarshaller.unmarshal(file);
return t;
TdeSerialize(Class docClass, InputStream inputStream)
Deserialize the XML content of a stream into a Java object of the specified type.
return deSerialize(docClass, new StreamSource(inputStream));
Objectdeserialize(Element elmnt, Class cls)
deserialize
final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller();
return um.unmarshal(elmnt);
Objectdeserialize(File fXMLFilePath, Class cls)
deserialize
final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller();
return um.unmarshal(fXMLFilePath);
Objectdeserialize(final Class clazz, final String json)
deserialize
ObjectMapper mapper = new ObjectMapper();
Object object = mapper.readValue(json, clazz);
return object;
Tdeserialize(Path input, Class clazz)
deserialize
InputStream in = new FileInputStream(input.toFile());
return deserialize(in, clazz);
Objectdeserialize(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);
...
TdeserializeFile(String path, Class clazz)
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) {
...
TdeserializeFromXmlFile(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;
SerializabledeserializeXmlToJava(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();
...