Here you can find the source of deserializeFromXmlFile(T defaultObject, String fileName)
@SuppressWarnings("unchecked") public static <T> T deserializeFromXmlFile(T defaultObject, String fileName)
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { @SuppressWarnings("unchecked") public static <T> T deserializeFromXmlFile(T defaultObject, String fileName) { T object = defaultObject;// w w w .j a v a 2s . c o m try { JAXBContext context = JAXBContext.newInstance(defaultObject.getClass()); try (FileInputStream inStream = new FileInputStream(fileName)) { object = (T) context.createUnmarshaller().unmarshal(inStream); } } catch (JAXBException | IOException e) { } return object; } }