This blog would be providing you one stop solution for the clean solutions towards solving the problem, instead of just giving just instruction and not actual code.

15 Oct 2013

JAXB unmarshal returns JAXBElement instead of root element

No comments :

If you are facing ClassCastException while unmarshaling XML using JAXB, it might be happening because unmarshalling is returning JAXBElement object.

Use below solution if JAXB unmarshaling returns JAXBElement.


JAXBContext jaxbContext = JAXBContext.newInstance("com.test.messaging");
 
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

JAXBElement jaxbResponse  =  (JAXBElement)jaxbUnmarshaller.unmarshal(file);

MessageType message = (MessageType )jaxbResponse.getValue();

No comments :

Post a Comment