public class JAXBContextUtil {
private static JAXBContext jaxbContext;
private JAXBContextUtil() {
}
public static synchronized JAXBContext getContext() throws JAXBException {
if (jaxbContext == null) {
jaxbContext = JAXBContext.newInstance(YourClass.class);
}
return jaxbContext;
}
}
JAXBContext jaxbContext = JAXBContext.newInstance(YourClass.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new FileInputStream("your_xml_file.xml"));
YourClass yourObject = (YourClass) unmarshaller.unmarshal(xmlStreamReader);