Here you can find the source of unmarshall(String file, Class
public static <T> T unmarshall(String file, Class<T> desiredClass, Class context) throws Exception
//package com.java2s; //License from project: Open Source License import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; import java.io.File; public class Main { public static <T> T unmarshall(String file, Class<T> desiredClass, Class context) throws Exception { JAXBContext ctx = JAXBContext.newInstance(context); Unmarshaller unMarshaller = ctx.createUnmarshaller(); JAXBElement<T> object = (JAXBElement<T>) unMarshaller.unmarshal(new File(file)); return object.getValue(); }// w w w.j a va2 s . co m }