Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings("unchecked") public static <T> T unmarshal(Class<T> clazz, InputStream is) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); return (T) um.unmarshal(is); } public static <T> T unmarshal(Class<T> clazz, String xml) throws JAXBException { return unmarshal(clazz, new ByteArrayInputStream(xml.getBytes())); } }