Here you can find the source of marshal(Object obj)
public static String marshal(Object obj) throws JAXBException
//package com.java2s; //License from project: Apache License import javax.xml.bind.*; import java.io.StringWriter; public class Main { public static String marshal(Object obj) throws JAXBException { return marshal(obj, obj.getClass()); }// w w w .ja v a 2 s . c om private static <T> String marshal(Object obj, Class<T> contextClass) throws JAXBException { final JAXBContext context = JAXBContext.newInstance(contextClass); final Marshaller marshaller = context.createMarshaller(); final StringWriter stringWriter = new StringWriter(); marshaller.marshal(obj, stringWriter); final String output = stringWriter.toString(); return output; } }