Here you can find the source of serialize(Object object, Class
public static <T> void serialize(Object object, Class<T> clazz, String filename) throws JAXBException
//package com.java2s; //License from project: LGPL import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static <T> void serialize(Object object, Class<T> clazz, String filename) throws JAXBException { JAXBContext context = JAXBContext.newInstance(clazz); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(object, new File(filename)); }/*from w ww. j av a2 s . c o m*/ }