Java tutorial
//package com.java2s; import javax.xml.bind.*; import java.io.StringReader; public class Main { public static <T> T xml2Object(String xml, Class<T> clazz) throws JAXBException { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); StringReader reader = new StringReader(xml); return (T) unmarshaller.unmarshal(reader); } }