Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
marco - 12 Jun 2006 09:31 GMT
Hi,

this problem occurs using JAXB with for unmarshalling an XML file.
The code is:

JAXBContext jc = JAXBContext.newInstance("Resource");
Unmarshaller u = jc.createUnmarshaller();

//u.setValidating(true);  //deprecated!!

MyResType res = (MyResType)u.unmarshal(new FileInputStream("foo.xml"));

Anyone can help?

Thanks
Oliver Wong - 12 Jun 2006 18:46 GMT
> Hi,
>
[quoted text clipped - 7 lines]
>
> MyResType res = (MyResType)u.unmarshal(new FileInputStream("foo.xml"));

   Use something like:

System.err.println(u.umarshal(new
FileInputStream("foo.xml")).getClass().getName());

   to get the actual type that's being returned, or use a debugger to
inspect the variable.

   - Oliver
marco - 13 Jun 2006 13:36 GMT
Thank you Oliver,

javax.xml.bind.JAXBElement is the actual type that is being returned.

I've read the documentation, but I wasn't able to solve this problem.

Oliver Wong ha scritto:

> > Hi,
> >
[quoted text clipped - 17 lines]
>
>     - Oliver
Oliver Wong - 13 Jun 2006 15:01 GMT
[post re-ordered]

> Oliver Wong ha scritto:
>
[quoted text clipped - 19 lines]
>
> javax.xml.bind.JAXBElement is the actual type that is being returned.

   You probably marshalled your data incorrectly then. Show the marshalling
code.

   - Oliver
marco - 13 Jun 2006 21:54 GMT
JAXBContext jax = JAXBContext.newInstance("Resource");
Marshaller m = jax.createMarshaller();
MyResType myRes = obj.createMyResType();
myRes.setBody("body"); //simple xsd:strings here
myRes.setHeader("header");

m.marshal(myRes, new FileOutputStream("foo.xml"));

thanks a lot!

Oliver Wong ha scritto:

> [post re-ordered]
>
[quoted text clipped - 26 lines]
>
>     - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.