Hi,

Something seems to have changed recently in the handling of Any objects. Used to be I 
got an object back when unmarshalling,
now I seem to get an AnyNode. I dont really know if this is a bug, or if I have to 
recursively unmarshal the anyobjects or something.

In any case, I wondered if anyobdy would be able to point me in the right direction - 
cos i would like to end up with an object!

Thanks for any help you might be able to offer!

Cheers

James

Using a schema that looks something like:

<xs:element name="body">
   <xs:complexType>
     <xs:sequence>
       <xs:any minOccurs="0" maxOccurs="unbounded"/>
     </xs:sequence>
   </xs:complexType>
</xs:element>

<xs:element name="message">
   <xs:complexType>
     <xs:sequence>
       <xs:element ref="body" minOccurs="1" maxOccurs="1"/>
     </xs:sequence>
   </xs:complexType>
</xs:element>

<xs:element name="event" >
   <xs:complexType>
     <xs:sequence>
       <xs:element ref="eventId" minOccurs="0" maxOccurs="1" />
       <xs:element ref="eventTime" minOccurs="0" maxOccurs="1" />
     </xs:sequence>
   </xs:complexType>
</xs:element>
</xs:schema>

If I put an event object into the body. Marshal to XML i get something like this:

<?xml version="1.0" encoding="UTF-8"?>
<message>
<body><event xsi:type="event" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<eventId>1</eventId>
<eventTime>1234567890</eventType>
</event>
</body>
</message>

I am doing the following ( paraphrased.. )

// Assume m is a message, with an event in it
StringWriter stringWriter = new StringWriter();
Marshaller marshaller = new Marshaller(stringWriter);
marshaller.marshal ( m, stringWriter );

String xml = stringWriter.toString();
System.out.println ( xml );

Object castorObject = Unmarshaller.unmarshal ( mypkg.Message.class, new StringReader ( 
xml ) );

mypkg.Message uMessage = ( mypkg.Message ) castorObject;

mypkg.Body uBody = uMessage.getBody();

Object[] uBodyObjects = uBody.getAnyObject();
System.out.println ( "BodyObjects is " + uBodyObjects.getClass().getName() );
Object ubo0 = uBodyObjects[0];

//Hmm getting any AnyNode here, not a mypkg.Event???

System.out.println ( "BodyObject[0] is " + ubo0.getClass().getName() );
org.exolab.castor.types.AnyNode anyNode = ( org.exolab.castor.types.AnyNode ) ubo0;

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to