Here you can find the source of convertXmlFileToObject(Class> clazz, String xmlPath)
public static Object convertXmlFileToObject(Class<?> clazz, String xmlPath)
//package com.java2s; import java.io.FileNotFoundException; import java.io.FileReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object convertXmlFileToObject(Class<?> clazz, String xmlPath) { Object xmlObject = null;//from w w w .java2 s. c o m try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); FileReader fr = null; try { fr = new FileReader(xmlPath); } catch (FileNotFoundException e) { e.printStackTrace(); } xmlObject = unmarshaller.unmarshal(fr); } catch (JAXBException e) { e.printStackTrace(); } return xmlObject; } }