Here you can find the source of xmlMarshal(Object obj, Class> clazz)
public static String xmlMarshal(Object obj, Class<?> clazz)
//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 xmlMarshal(Object obj, Class<?> clazz) { StringWriter stringWriter = new StringWriter(); try {//from ww w. ja va 2s .c om JAXBContext context = JAXBContext.newInstance(clazz); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(obj, stringWriter); } catch (JAXBException e) { e.printStackTrace(); } return stringWriter.toString(); } }