Here you can find the source of marshalObject(Object obj, File file)
public static void marshalObject(Object obj, File file)
//package com.java2s; //License from project: Apache License import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void marshalObject(Object obj, File file) { try {/*from w w w .ja v a 2s . c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance("com.osafe.feeds.osafefeeds"); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "Unicode"); jaxbMarshaller.marshal(obj, file); } catch (JAXBException e) { e.printStackTrace(); } } public static void marshalObject(Object obj, String fileStr) { File file = new File(fileStr); marshalObject(obj, file); } }