
ru.greatbit.utils.serialize.xml.XMLMarshaller Maven / Gradle / Ivy
package ru.greatbit.utils.serialize.xml;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.IOException;
import java.io.StringWriter;
/**
* Created by azee on 4/17/14.
*/
public class XMLMarshaller {
/**
* Marhsal an object to string
* @param instance
* @return
* @throws IOException
* @throws JAXBException
*/
public static String marshal(Object instance) throws IOException, JAXBException {
JAXBContext contextA = JAXBContext.newInstance(instance.getClass());
Marshaller marshaller = contextA.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshal(instance, writer);
return writer.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy