Rick-

Ah... That makes life a little more difficult doesn't it. Yes, with my solution, the element name will always be callee and the xsi:type will specify "ThisClass" or "ThatClass". Since you require the element name to change we'll have to dig a little deeper to find out why the one solution works while the other doesn't.

Sorry for the confusion, I guess I should have read your first e-mail a little more carefully. I'll look into it and see what I can find.

Stephen


Fishman, Richard wrote:
Thanks Stephen but, if I understand your solution, it unfortunately won't work 
for me in this situation.

If I understand your solution, 'callee' will be the xml tag name, not ThisClass 
or ThatClass. Is this correct?

If so, the XML has to have the ThisClass or ThatClass tag name because the 
marshalled xml is actually going to another application which expects that tag 
name and doesn't use Castor. The issue that I have is my emulator that I use 
when testing without the other application. In that case I am using Castor to 
unmarshall. So with your suggestion, my emulator will work fine but the 
proudction app won't.

If I did not understand your solution correctly, I apologize but could you elaborate just a bit?
-----Original Message-----
From: Stephen Bash [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 18, 2006 10:16 AM
To: [email protected]
Subject: Re: [castor-user] [XML] Any way to have Castor infer type from object 
and serialize it?

Rick-

I was able to reproduce your error, and I agree with Werner, I don't know why 
it comes up.  But by not using auto-naming, I was able to get the code to 
unmarshal successfully (must be a different branch of logic).  So all I changed 
was the mapping of CallObject:

    <class name="CallObject">
       <map-to xml="CallObject" />
       <field name="object" type="java.lang.Object">
          <bind-xml name="callee" />
       </field>
    </class>

This does mean the xsi:type attribute is required, because otherwise Castor 
won't know what class to instantiate.

Hopefully this solution is amenable to your situation.

Stephen


Fishman, Richard wrote:

Werner, I am using packages. These are just examples to make the testcase understandable.
-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 18, 2006 9:45 AM
To: [email protected]
Subject: RE: [castor-user] [XML] Any way to have Castor infer type from object 
and serialize it?

Richard,

What surprises me is that the XML as marshalled by Castor still includes the xsi:type="ThisClass" directive. Apart from that, can you please consider starting to use packages? Afair, Castor (XML or/and JDO) uses (used) to have problems with classes in the standard root package.
Thanks
Werner



-----Original Message-----
From: Fishman, Richard [mailto:[EMAIL PROTECTED]
Sent: Mittwoch, 18. Jänner 2006 15:34
To: [email protected]
Subject: RE: [castor-user] [XML] Any way to have Castor infer type

from object and serialize it?

Yes, this is my mapping xml now:
        <class name="CallObject">
                <map-to xml="CallObject" />
                        <field name="object" type="java.lang.Object">
                                <bind-xml auto-naming="deriveByClass" />
                        </field>  
        </class>
        <class name="ThisClass">
                <map-to xml="ThisClass"/>
                <field name="xx" type="java.lang.String">
                        <bind-xml name="xx" node="element"/>
                </field>
        </class>
        <class name="ThatClass">
                <map-to xml="ThatClass"/>
                <field name="yy" type="java.lang.String">
                        <bind-xml name="yy" node="element"/>
                </field>
        </class>

The XML that was marshalled (and is attempted to be
unmarshalled) looks like this:
<CallObject><ThisClass
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:type="ThisClass"><xx>something</xx></ThisClass></CallObject>

-----Original Message-----
From: Stephen Bash [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 18, 2006 9:26 AM
To: [email protected]
Subject: Re: [castor-user] [XML] Any way to have Castor infer type

from object and serialize it?

Rick-

Does ThisClass have a mapping anywhere that Castor knows about? That would give Castor a hard reference between the element name and the fully qualified class name which might help.

Stephen


Fishman, Richard wrote:


Thanks! That works great for marshalling the XML.

Unmarshalling is getting an error though:

org.xml.sax.SAXException: unable to find FieldDescriptor for 'ThisClass' in ClassDescriptor of CallObject at


org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.j


ava:1933) at


org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.j


ava:1381) at
org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
Source)

Any ideas?

-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 18, 2006 8:49 AM
To: [email protected]
Subject: RE: [castor-user] [XML] Any way to have Castor

infer type from object and serialize it?


Hi,

A field mapping similar to

<field name="object" type="java.lang.Object"

collection="collection">

        <bind-xml auto-naming="deriveByClass"></bind-xml>
</field>

should do the trick in your case. Have a look at

http://castor.codehaus.org/xml-mapping.html#5.-xsi:type for more details.


Regards
Werner




-----Original Message-----
From: Fishman, Richard [mailto:[EMAIL PROTECTED]
Sent: Mittwoch, 18. Jänner 2006 14:44
To: [email protected]
Subject: [castor-user] [XML] Any way to have Castor infer type from object and serialize it?

We have a class called CallObject and it contains one

member variable


whose type can change. We want to be able to have The CallObject contain an Object and have Castor serialize it

appropriately based on


the class of the object.

In other words, we want a class like this:

Public class CallObject
{
        private Object theObj;
        public void setObject(Object o)
        {
                this.theObj = 0;
        }
}

Then clients would call setObject with whatever they want in that 'call object'. For example:

callObj.setObject(new ThisClass());

Or

callObj.setObject(new ThatClass());

The mapping.xml would have rules for CallObject as well as

ThisClass


and
ThatClass:
        <class name="CallObject">
                <map-to xml="CallObject"/>
        </class>
        <class name="ThisClass">
                <map-to xml="ThisClass"/>
                <field name="xx" type="java.lang.String">
                        <bind-xml name="xx" node="element"/>
                </field>
        </class>
        <class name="ThatClass">
                <map-to xml="ThatClass"/>
                <field name="yy" type="java.lang.String">
                        <bind-xml name="yy" node="element"/>
                </field>
        </class>

Then depending on what was set into callObj, the

appropriate XML would


be generated, either:
<CallObject>
        <ThisClass>
                <xx>something</xx>
        </ThisClass>
</CallObject>

Or

<CallObject>
        <ThatClass>
                <yy>somethingElse</yy>
        </ThatClass>
</CallObject>

Is this possible to do? If so, how do you do it?


Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this

e-mail do not


reflect the views of Blue Cross Blue Shield of Florida, Inc. The information contained in this document may be confidential and intended solely for the use of the individual or entity to

whom it is


addressed.  This document may contain material that is

privileged or


protected from disclosure under applicable law. If you are not the intended recipient or the individual responsible for

delivering to the


intended recipient, please (1) be advised that any use,

dissemination,


forwarding, or copying of this document IS STRICTLY PROHIBITED; and
(2) notify sender immediately by telephone and destroy the

document.

THANK YOU.



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------





-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------







Blue Cross Blue Shield of Florida, Inc., and its subsidiary

and affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc. The information contained in this document may be confidential and intended solely for the use of the individual or entity to whom it is addressed. This document may contain material that is privileged or protected from disclosure under applicable law. If you are not the intended recipient or the individual responsible for delivering to the intended recipient, please (1) be advised that any use, dissemination, forwarding, or copying of this document IS STRICTLY PROHIBITED; and (2) notify sender immediately by telephone and destroy the document. THANK YOU.



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------







Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc. The information contained in this document may be confidential and intended solely for the use of the individual or entity to whom it is addressed. This document may contain material that is privileged or protected from disclosure under applicable law. If you are not the intended recipient or the individual responsible for delivering to the intended recipient, please (1) be advised that any use, dissemination, forwarding, or copying of this document IS STRICTLY PROHIBITED; and (2) notify sender immediately by telephone and destroy the document. THANK YOU.



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------





-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------







Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate 
companies are not responsible for errors or omissions in this e-mail message. 
Any personal comments made in this e-mail do not reflect the views of Blue 
Cross Blue Shield of Florida, Inc.  The information contained in this document 
may be confidential and intended solely for the use of the individual or entity 
to whom it is addressed.  This document may contain material that is privileged 
or protected from disclosure under applicable law.  If you are not the intended 
recipient or the individual responsible for delivering to the intended 
recipient, please (1) be advised that any use, dissemination, forwarding, or 
copying of this document IS STRICTLY PROHIBITED; and (2) notify sender 
immediately by telephone and destroy the document. THANK YOU.



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the 
following address:

[EMAIL PROTECTED]
-------------------------------------------------







Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate 
companies are not responsible for errors or omissions in this e-mail message. 
Any personal comments made in this e-mail do not reflect the views of Blue 
Cross Blue Shield of Florida, Inc.  The information contained in this document 
may be confidential and intended solely for the use of the individual or entity 
to whom it is addressed.  This document may contain material that is privileged 
or protected from disclosure under applicable law.  If you are not the intended 
recipient or the individual responsible for delivering to the intended 
recipient, please (1) be advised that any use, dissemination, forwarding, or 
copying of this document IS STRICTLY PROHIBITED; and (2) notify sender 
immediately by telephone and destroy the document. THANK YOU.



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to