Here you can find the source of marshal(T object)
@SuppressWarnings("unchecked") public static <T> String marshal(T object) throws IOException, JAXBException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { @SuppressWarnings("unchecked") public static <T> String marshal(T object) throws IOException, JAXBException { Class<T> clzz = (Class<T>) object.getClass(); JAXBContext context;//from w ww. ja va 2 s . c o m context = JAXBContext.newInstance(clzz); Marshaller m = context.createMarshaller(); ByteArrayOutputStream os = new ByteArrayOutputStream(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(object, os); return os.toString(); } }