Here you can find the source of marshal(final Object object)
public static String marshal(final Object object)
//package com.java2s; //License from project: Open Source 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(final Object object) { try {//from ww w . j a v a2 s . com final JAXBContext context = JAXBContext.newInstance(object.getClass()); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); final StringWriter out = new StringWriter(); marshaller.marshal(object, out); return out.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } }