Here you can find the source of xml2Object(String content, Class
@SuppressWarnings("unchecked") public static <T> T xml2Object(String content, Class<T> valueType)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayInputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings("unchecked") public static <T> T xml2Object(String content, Class<T> valueType) { try {// w w w. j ava 2 s .c o m JAXBContext jaxbContext = JAXBContext.newInstance(valueType); Unmarshaller um = jaxbContext.createUnmarshaller(); T t = (T) um.unmarshal(new ByteArrayInputStream(content.getBytes())); return t; } catch (JAXBException e) { //System.out.println("JAXB castor failed to convert the metadata to module instance."); } return null; } }