Java tutorial
//package com.java2s; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.StringReader; public class Main { @SuppressWarnings("unchecked") public static <T> T xmlToObject(String str, Class<T> clszz) { JAXBContext context = null; T obj = null; try { context = JAXBContext.newInstance(clszz); StringReader reader = new StringReader(str); Unmarshaller unmar = context.createUnmarshaller(); obj = (T) unmar.unmarshal(reader); } catch (JAXBException e) { e.printStackTrace(); } return obj; } }