John,

Ah ok...yes Castor will not marshal null values.

The problem is how to differential between Null and empty.

For example:

String foo = ""; 

is different than

String foo = null;

Castor will marshal the first value as <foo/>

The second value will not get marshalled.

Currently there is no way to treat null values as the same as empty
values. 

--Keith


"Goyer, John" wrote:
> 
> Keith,
> 
> Thanks for the quick response. Actually I did have the
> "extends" attrib in there correctly; I screwed up in
> cutting and pasting.
> 
> It turns out that the attribute wasn't appearing because
> if it is null, Castor ignores it.  I would like empty
> tags to appear for nulls -- can this be done?
> 
> Thanks,
> 
> John Goyer
> 
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 08, 2003 5:06 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] XML Mapping of Subclass?
> 
> Hi John,
> 
> You need to specify the extends attribute on the class mapping as such:
> 
>  <class name="example.Lodging" extends="example.Option"
> auto-complete="false">
>    <field name="lodgeType" type="integer"></field>
>  </class>
> 
> --Keith
> 
> "Goyer, John" wrote:
> >
> > I have a simple class hierarchy.
> >
> > Class Option  { protected String optionPk; }
> >
> > Class LodgingOption extends Option { protected int lodgeType; etc... }
> >
> > I can serialize B to XML using Castor, but it will not include the
> > data members inherited from A.  Is this a limitation of
> > Castor?  I have tried the following mappng file.  It has no effect.
> > The file below simply produces an XML doc with the lodgeType but
> > nothing more.  Code is below the map file.  Thanks!
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
> > 1.0//EN"
> > "http://castor.exolab.org/mapping.dtd";>
> >
> > <mapping>
> >
> > <description>
> >   Maps a Lodging instance to an XML representation.
> > </description>
> >
> > <class name="example.Option">
> >     <field name="optionPk"></field>
> > </class>
> >
> > <class name="example.Lodging"
> >   auto-complete="false" name="example.Option">
> >   <field name="lodgeType"></field>
> > </class>
> >
> > </mapping>
> >
> > ------- Code -------------------------------------------------------------
> >
> >      public String toXML( Object obj ) throws MarshalException,
> > ValidationException {
> >
> > //        init();
> > //        StringWriter sw = new StringWriter();
> > //        Marshaller.marshal( obj, sw );
> > //        return sw.toString();
> > //
> >         init();
> >         StringWriter sw = new StringWriter();
> >         Marshaller m = null;
> >         try {
> >
> >             Mapping mapping = new Mapping();
> >             mapping.loadMapping( baseDir + mapDir +
> > "Lodging.castormap.xml");
> >
> >             m = new Marshaller(sw);
> >             m.setMapping( mapping );
> >
> >         } catch (IOException e) {
> >             // TODO Auto-generated catch block
> >             e.printStackTrace();
> >         } catch (MappingException e) {
> >             // TODO Auto-generated catch block
> >             e.printStackTrace();
> >         }
> >         m.marshal( obj );
> >
> >         return sw.toString();
> >
> >     }
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

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

Reply via email to