Here you can find the source of marshallerObject(Class c, Object o)
public static String marshallerObject(Class c, Object o)
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Main { public static String marshallerObject(Class c, Object o) { String s = "<?xml version=\"1.0\" ?>"; try {/*from w ww . java 2s. c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(c); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter baos = new StringWriter(); marshaller.marshal(o, baos); s += baos.toString(); } catch (Exception e) { } return s; } }