Here you can find the source of marshal(Object bean)
public static String marshal(Object bean) throws JAXBException
//package com.java2s; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.OutputStream; import java.io.StringWriter; public class Main { private static JAXBContext jaxbContext; private static ThreadLocal<Marshaller> marshaller = new ThreadLocal<Marshaller>(); public static String marshal(Object bean) throws JAXBException { StringWriter writer = new StringWriter(); getMarshaller().marshal(bean, writer); return writer.toString(); }// ww w . j a v a 2 s . co m public static void marshal(Object bean, OutputStream os) throws JAXBException { getMarshaller().marshal(bean, os); } private static Marshaller getMarshaller() throws JAXBException { Marshaller m = marshaller.get(); if (m == null) { m = jaxbContext.createMarshaller(); marshaller.set(m); } return m; } }