Here you can find the source of marshal(final Object obj, final Class... classes)
public static String marshal(final Object obj, final Class... classes) throws JAXBException
//package com.java2s; /*//ww w .jav a 2 s . co m * Copyright (2009) Schibsted ASA * This file is part of Sesat Commons. * * Sesat Commons is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Sesat Commons is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Sesat Commons. If not, see <http://www.gnu.org/licenses/>. */ import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { /** JAXBContext.newInstance(..) is a slow operation. * @deprecated It is better the client creates the JAXBContent once and re-uses it to the other marshal method. */ public static String marshal(final Object obj, final Class... classes) throws JAXBException { return marshal(JAXBContext.newInstance(classes), obj); } public static String marshal(final JAXBContext context, final Object obj) throws JAXBException { final StringWriter out = new StringWriter(); context.createMarshaller().marshal(obj, out); return out.toString(); } }