Java tutorial
//package com.java2s; import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings("unchecked") public static <T> T convertToObject(String xml, Class<T> type) { StringReader sr = new StringReader(xml); try { JAXBContext jAXBContext = JAXBContext.newInstance(type); Unmarshaller unmarshaller = jAXBContext.createUnmarshaller(); return (T) unmarshaller.unmarshal(sr); } catch (JAXBException e) { throw new RuntimeException(e); } } }