Java tutorial
//package com.java2s; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static File Marshall(Object object, String filePath) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(object.getClass()); Marshaller u = jc.createMarshaller(); u.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); File f = new File(filePath); u.marshal(object, f); return f; } }