Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type safety: Unchecked cast from Object to JAXBElement<User>

Tags:

java

xml

jaxb

xsd

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); 
like image 253
Hann Avatar asked Jan 10 '23 17:01

Hann


1 Answers

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.

like image 186
bdoughan Avatar answered Jan 13 '23 06:01

bdoughan