Here you can find the source of unmarshalFromXml(Class
public static <T> T unmarshalFromXml(Class<T> clazz, String xml) throws JAXBException, UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import javax.xml.bind.*; import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; public class Main { public static <T> T unmarshalFromXml(Class<T> clazz, String xml) throws JAXBException, UnsupportedEncodingException { final JAXBContext context = JAXBContext.newInstance(clazz); return unmarshalFromXml(context, clazz, xml); }//from w w w . jav a 2 s .c o m @SuppressWarnings("unchecked") private static <T> T unmarshalFromXml(JAXBContext context, Class<T> clazz, String xml) throws JAXBException, UnsupportedEncodingException { final Unmarshaller um = context.createUnmarshaller(); final ByteArrayInputStream input = new ByteArrayInputStream(xml.getBytes("UTF-8")); return (T) um.unmarshal(input); } }