I have a similar problem.  An external system is sending us empty tags if a
field has no data.  The problem is that when we convert it to our schema we
run into validation problems.
e.g. we have a 'telephone' element that has a regular expression of between
9 and 13 digits.  If we put the empty data into this element then it falls
over because it does not meet the regular expression.  Similarly we have
elements like 'initials' that is a string of min length 1.

The only way I can see around this at the moment is to check every element
in the external message and only if it is not empty, then assign it to our
message.  Our assumption has always been if a field does not include any
data then don't include the tags.  Any suggestions?

Thanks

Jenny

Keith Visco <[EMAIL PROTECTED]> on 08/07/2002 18:35:40

Please respond to [EMAIL PROTECTED]

To:    [EMAIL PROTECTED]
cc:
Subject:    Re: [castor-dev] Mapping NULL values




Hi Richard,

We treat null and empty element different. An empty element is not null,
it exists...it just doesn't have any properties set. Consider the
following:

public String getTAG();

if the getTAG method returns an empty string (""), then  <TAG></TAG>
will be output.

An empty string is definately different than a null string. So if the
getTAG method returns null we don't output the <TAG>.

Now consider the following object:

public class Foo {
   public String getName();
}

and the following method:

public Foo getFoo();

If getFoo returns A Foo object, with no name the following will be
output:
<foo></foo>

if the foo object has a name, then the following will be output:

<foo><name>foo1</name></foo>

-or-

<foo name="foo1"></foo>

depending on how Castor is configured.

if the foo object is null, no tag will be output.

If we output <foo></foo> for a null foo object, then we wouldn't be able
to differentiate between when we have a foo with no properties, or when
we have a no foo at all.

You see the problem?

Currently there is no way for you to set Castor to handle null the same
way it handles an empty object. There would be no way for Castor to
determine upon unmarshalling whether or not an instance of the object
should be created or not.


--Keith

Richard Bourland wrote:
>
> Does anyone have an example of how to map a NULL value with Castor? My
>
> goal is to get the null value to map to an empty element or just have
> the tag get mapped (i.e. <TAG></TAG>). I understand that castor will
> not
> map a null value to xml. I am looking for a way to override this
> behavior. I have found some references to using a custom FieldHandler
> but I
> cant find a concrete example of it? Is there a property or tag in the
> mapping file that can override this behavior?
>
> Thanks in advance,
>
> ------------------------------
> email - [EMAIL PROTECTED]
> Home - 972.869.9878
> Cell - 972.567.7536
> ------------------------------
>
> ----------------------------------------------------------------------
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax

-----------------------------------------------------------
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