Here you can find the source of toObject(Class className, String strXml)
public static Object toObject(Class className, String strXml)
//package com.java2s; //License from project: Apache License import java.io.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { public static Object toObject(Class className, String strXml) { Object object = null;//from w ww. j av a2 s. c o m StringReader reader = null; try { reader = new StringReader(strXml); JAXBContext context = JAXBContext.newInstance(className); Unmarshaller unmarshaller = context.createUnmarshaller(); object = unmarshaller.unmarshal(reader); } catch (Exception e) { } finally { if (reader != null) { reader.close(); reader = null; } } return object; } }