Here you can find the source of unmarshalByContent(Class
@SuppressWarnings("unchecked") public static <T> T unmarshalByContent(Class<T> clazz, String xmlContent)
//package com.java2s; //License from project: Open Source License import com.google.common.io.Closeables; import com.google.common.io.Resources; import javax.xml.bind.JAXBContext; import java.io.*; import java.net.URL; public class Main { @SuppressWarnings("unchecked") public static <T> T unmarshalByContent(Class<T> clazz, String xmlContent) { Reader reader = null;//ww w .j av a 2s. c om try { reader = new StringReader(xmlContent); JAXBContext context = JAXBContext.newInstance(clazz); return (T) context.createUnmarshaller().unmarshal(reader); } catch (Exception e) { throw new RuntimeException( "Failed to unmarshal object for class:" + clazz + " xmlContent:" + xmlContent, e); } finally { Closeables.closeQuietly(reader); } } public static <T> T unmarshal(Class<T> clazz, String xmlInClassPath) { Reader reader = null; try { URL xmlUrl = Resources.getResource(xmlInClassPath); reader = new InputStreamReader(xmlUrl.openStream(), "UTF-8"); JAXBContext context = JAXBContext.newInstance(clazz); return (T) context.createUnmarshaller().unmarshal(reader); } catch (Exception e) { throw new RuntimeException("Failed to unmarshal object for class:" + clazz + " xml:" + xmlInClassPath, e); } finally { Closeables.closeQuietly(reader); } } }