Hope the sample code redeems someone’s frustration:. Philippe Philippe 9 Sign up using Facebook. When debug the content received, is a list with the next content: Trying to get past a class cast exception here: Just make a note here. Please add more to the answer that explains why the OP should use your code and how it solves their issue. If it is still relevant today, there is a way to solve this issue in the config file.

I’m still trying to figure out why there’s a ClassCastException. Exception in thread “Main Thread” javax. In factor the “generated” can be placed anywhere as long as the parent directory is in the classpath. In my case I used: Sign up or log in Sign up using Google. I think the directory structure of my very simple first project is in proper order shown below:

Something just does not match up Email Required, but never shown. Sign up using Facebook. I wonder what the reason is. We spent too many hours fidgeting with the JAXB factory class to satisfy the unmarshaller.

Trying to get past a class cast exception here: In my case I used:. Cannot find the declaration of element ‘problemBean’. Please make it clearer.


cannot be cast to javax.xml.bind.JAXBElement

Such an object cannot be casted to gov. The error was resolved in a weird way, I have to change the jaxbelemeng element in my xsd file to note: It turns out that your XSD must be properly set up, i. Greg Noe Greg Noe 9 Just make a note here.

I’d look at the XML canbot and make sure it is roughly what you expect to see. I first converted a Java Bean ProblemBean.

java.lang.ClassCastException: javax.xml.bind.JAXBElement

Here is the very simple XSD file problem. Sign up using Email and Password.

I have about the same configurations as you. It’s been a long time, but if I remember correctly, the object here represents your POJO, use your class instead and unmarshal to an instance of it. I need to set the property ‘strip whitespaces’ to true to skip this error. Sign up or log in Sign up using Google.

But apparently the unmarshalling process produces a bine. Sign up using Facebook. By re-reading now your post, I come to the conclusion that I must have prepared my response based on some unedited version of your original post. All the more delicate elements are mentioned in the couple of posts above.


ProblemBean, the two are completely different classes. If the first one failes then the class cast is happening inside the unmarshal method, if it succeeds then you can see the actual class that you are getting back and then figure out why it isn’t what you expect it to be.

Now, I have another question: Pass – I only investigated far enough to solve the original problem: If the “grandparent” y is in the classpath, like this: Are you absolutely sure FooClass is the root element of the xml input source you passed it?

ement cannot be cast to

I’d also temporarily change the code to: In fact, jaxb generates xml jaxbelemdnt some adjustment by default such as leaving the first letter in lower case, also such as collapsing underscore etc The root element of the document is named “ProblemBean” not “Problem”.

At least we have a workaround I also encountered the “Javax. Marek Branicky Marek Branicky 11 1 3.