Here you can find the source of unmarshallString(String str, Class
@SuppressWarnings("unchecked") public static <T> T unmarshallString(String str, Class<T> c) throws IOException, JAXBException
//package com.java2s; //License from project: GNU General Public License import java.io.ByteArrayInputStream; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { private static JAXBContext jc = null; private static Unmarshaller um = null; @SuppressWarnings("unchecked") public static <T> T unmarshallString(String str, Class<T> c) throws IOException, JAXBException { initUnmarshaller(c);//from ww w.j a v a2s . co m ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes()); return (T) um.unmarshal(bis); } private static final <T> void initUnmarshaller(Class<T> c) throws JAXBException { jc = JAXBContext.newInstance(new Class[] { c }); um = jc.createUnmarshaller(); } }