ObjectToXml.java 715 Bytes
Newer Older
ED-DRIF committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package com.fractalite.hermes.teldar.tools;


import java.io.ByteArrayOutputStream;

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

public class ObjectToXml {

	public static String printXML(final Object object) {
		
		ByteArrayOutputStream s = new ByteArrayOutputStream();
		
		JAXBContext jc;
		try {
			jc = JAXBContext.newInstance(object.getClass());
	        Marshaller marshaller = jc.createMarshaller();
	        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	        marshaller.marshal(object, s);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		return s.toString();
		
	}
}