Here you can find the source of fromXML(String xml, Class
@SuppressWarnings({ "unchecked", "restriction" }) public static <T> T fromXML(String xml, Class<T> valueType)
//package com.java2s; //License from project: Apache License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings({ "unchecked", "restriction" }) public static <T> T fromXML(String xml, Class<T> valueType) { try {/*from w w w. j a va 2 s . c o m*/ JAXBContext context = JAXBContext.newInstance(valueType); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }