Since java objects (unlike c++ objects) do not change their type when they
are 'cast' the castor behavior is correct. In fact, the cast is essentially
meaningless - at runtime you have a Something or a SomeOtherThing not simply
a Base. You could obviously create a Base instance using the object you have
(via clone or copy constructor on Base) and then marshall this instance. 

Jay

-----Original Message-----
From: Rick Ross [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 14, 2004 1:11 AM
To: [EMAIL PROTECTED]
Subject: [castor-user] [XML] Inheritance and mapping the base class.



Hi.  I have some base classes I use for a group of classes.  Something like:

public class Base {
   // a bunch of bean style getters and setters.
}

public class Something extends Base {
   // different getters and setters
}

public class SomeOtherThing extends Base {
   // you get the picture...
}

When objects are instantiated, they are always instantiated as Something or
SomeOtherThing objects.  When I go to marshall them, I always cast them into
Base objects because that is all I want marshalled. However, I always get
the fields from Something and SomeOtherThing.  

In fact, in the xml output, the class attribute is always the fully
qualified class name of the instantiated class, not the base class.

I have tried a mapping and using the "extends" attribute, but that did not
work either.  In that case, the output had something like some-other-thing
as the class name, which I seem to recall is a castor name mangling
convention.

I thought I could do this in the mapping :

<class name="SomeOtherThing" extends="Base" />
<class name="Base">
   ... all of my mapping for the base class fields here.
</class>

Can anyone offer a bit of insight?   Am I just missing the concept or
missing a setting?  

Thanks

Rick
 

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

Reply via email to