Here you can find the source of createObject(String xml, Object type)
public static Object createObject(String xml, Object type) throws Exception
//package com.java2s; //License from project: LGPL import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { public static Object createObject(String xml, Object type) throws Exception { JAXBContext jc = JAXBContext.newInstance(type.getClass()); //JAXBContext jc = JAXBContext.newInstance(className); Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8")); Object obcj = unmarshaller.unmarshal(stream); return obcj; }//from w ww. ja v a 2s . c o m }