用JAXB技术时,遇到了cannot be cast to javax.xml.bind.JAXBElement 异常。google了一些,发现了一篇国外的文章:
http://metro.1045641.n5.nabble.com/cannot-be-cast-to-javax-xml-bind-JAXBElement-td1051377.html
仔细研究了一下,发现了这样的话,
In your case you don't need to use JAXBElement at all, because your class (Instrucciones) has @XmlRootElement annotation. So you may simply do something like this:
Instrucciones po = (Instriccones) u.unmarshal( new FileInputStream( "src/tests/ejemploAlumnos1.xml" ));
If you want to use JAXBElement for some reason, you can do
JAXBElement<Instrucciones> jxbElem = u.unmarshal( new FileInputStream( "src/tests/ejemploAlumnos1.xml" ), Instrucciones.class);
于是按照他说的,改了下,果然正确。