Here you can find the source of unmarshal(final String xml, final Class
public static <T extends Object> T unmarshal(final String xml, final Class<T> clazz) throws JAXBException
//package com.java2s; /*/*from w ww . j a va2 s .c o 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.StringReader; 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 unmarshal method. */ public static <T extends Object> T unmarshal(final String xml, final Class<T> clazz) throws JAXBException { return (T) unmarshal(JAXBContext.newInstance(clazz), xml); } public static Object unmarshal(final JAXBContext context, final String xml) throws JAXBException { return context.createUnmarshaller().unmarshal(new StringReader(xml)); } }