Here you can find the source of stringToObject(String s, Class theclass)
public static Object stringToObject(String s, Class theclass) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object stringToObject(String s, Class theclass) throws JAXBException { Object o = null;// ww w .jav a 2 s . c om ByteArrayInputStream input = new ByteArrayInputStream(s.getBytes()); JAXBContext jaxbContext = JAXBContext.newInstance(theclass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); o = theclass.cast(jaxbUnmarshaller.unmarshal(input)); return o; } }