Here you can find the source of fromXml(InputStream input, Class
@SuppressWarnings("unchecked") public static <T> T fromXml(InputStream input, Class<T> clazz)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static final String CHARSET = "UTF-8"; @SuppressWarnings("unchecked") public static <T> T fromXml(InputStream input, Class<T> clazz) { try {//from w w w .ja va2 s. co m JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new InputStreamReader(input, CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } return null; } public static <T> T fromXml(String xmlStr, Class<T> clazz) { return fromXml(new ByteArrayInputStream(xmlStr.getBytes(Charset.forName(CHARSET))), clazz); } }