users@jaxb.java.net

Re: ClassCastException when Unmarshalling

From: David Massart <david.massart_at_LONGBOY.EUN.ORG>
Date: Thu, 12 Jun 2003 02:26:38 -0600

Ed,

On Wed, 11 Jun 2003 10:52:51 -0400, Ed Mooney <Ed.Mooney_at_Sun.COM> wrote:

>Most likely this is a classloader issue. Search the archives for
>"classloadingFAQ" for Kohuske's exposition.
>

I think my problem is different, I've tried the following code and the error occurs when unmarshalling, not when casting.

David

try
{
     JAXBContext jc = JAXBContext.newInstance("org.eun.celebrate.xml.ns.message_0_1", this.getClass().getClassLoader() );
     Unmarshaller u = jc.createUnmarshaller();
     // u.setValidating(true);
     Object o = u.unmarshal(new javax.xml.transform.stream.StreamSource(new StringReader(s.toString())));
     org.eun.celebrate.xml.ns.message_0_1.MessageType m = (org.eun.celebrate.xml.ns.message_0_1.MessageType) o;
}
catch (Exception e)
{
    e.printStackTrace() ;
}


>Regards,
>--
>Ed Mooney |Sun Microsystems, Inc.|Time flies like
>Java Web Services |UBUR02-201 |an arrow, but
>Ed.Mooney_at_Sun.COM |1 Network Drive |fruit flies like
>781-442-0459 |Burlington, MA 01803 |a banana. Groucho
>
>David Massart wrote:
>> Hi There,
>>
>> I got the following exception when I try to unmarshal a xml document on the Sun One AppServ 7 whereas I have no problem to unmarshal it with a standalone application.
>>
>> I use JAXB 1.0.1 and JAXB classes are generated with the necessary extension in order to have them serializable.
>>
>> java.lang.ClassCastException at org.eun.celebrate.xml.ns.root.impl.runtime.AbstractUnmarshallingEventHandlerImpl.spawnChild(AbstractUnmarshallingEventHandlerImpl.java:203)
>> at org.eun.celebrate.xml.ns.root.impl.runtime.AbstractUnmarshallingEventHandlerImpl.spawnChildFromEnterAttribute(AbstractUnmarshallingEventHandlerImpl.java:224)