Here you can find the source of marshal(Object object)
public static String marshal(Object object)
//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 { public static String marshal(Object object) { try {/*from w ww .j a v a 2 s. c om*/ StringWriter writer = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(object, writer); return writer.toString(); } catch (JAXBException e) { throw new RuntimeException("Error marshalling object", e); } } }