Question

i have a prob with a cast

JAXBElement<User> jaxbElement = (JAXBElement<User>)unmarshaller.unmarshal(sr); 

It's doesn't work , eveybody can help me ?


I can't do this : i show you my code :

StringReader sr = new StringReader(this.message);
JAXBElement<Utilisateur> jaxbElement = (JAXBElement<Utilisateur>) unmarshaller.unmarshal(sr);   

if I do this, I have an error because i Use a StringReader :

JAXBElement<User> jaxbElement = unmarshaller.unmarshal(sr, User.class); 
Was it helpful?

Solution

If you want to avoid the compiler warning you can use one of the unmarshal methods that takes a Class parameter.

JAXBElement<User> jaxbElement = unmarshaller.unmarshal(sr, User.class);

Note

Your code should run perfectly fine as you have it in your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top