Java XML JAXB Unserialize unserialize(T component, Class returnType)

Here you can find the source of unserialize(T component, Class returnType)

Description

unserialize

License

Apache License

Declaration

public static <T> String unserialize(T component, Class<T> returnType) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    private static JAXBContext JAXBCONTEXT = null;

    public static <T> String unserialize(T component, Class<T> returnType) {

        try {//from   ww  w.j  ava2  s.com
            Marshaller marshaller = JAXBCONTEXT.createMarshaller();

            StringWriter sw = new StringWriter();
            marshaller.marshal(component, sw);
            return sw.toString();

        } catch (JAXBException je) {
            return "failed";
        }
    }
}

Related

  1. readJaxbObject(InputStream inputStream, Class jaxbModelClass)
  2. readObject(Class clazz, File file)
  3. readObjectFromInputStream(final InputStream inputStream, final Class expectedType)
  4. readObjectFromXml(Class jaxbBindClass, String xmlFileName)
  5. readXmlFileToObj(String path, String packageName)