Keith:
Thanks for the tip. My question is this: Will this "feature" ever be coded
out or removed? If so, I cannot use it reliably - the stuff I am working on
will likely ship to hundreds of sites, and if it were ever removed as a
feature we would have some serious difficulties.
Thanks.
> Joe Kathan
> Medic Computer Systems, LLC
> <mailto:[EMAIL PROTECTED]>
> (919)-847-8102 x1862
> Views expressed by the author do not necessarily represent those of Medic
Computer Systems, LLC management and Board of Directors
>
-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 03, 2001 5:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] XML mapping question
Hi Joe,
Here is the undocumented tip of the week ;-)
It's not directly supported...however, there is a little hack you can do
that'll
make it work for you.
Add the following to your class mapping:
<!-- hack to ignore unmatched elements -->
<field name="anything" type="string" get-method="toString"
transient="true">
<bind-xml node="element" matches="*"/>
</field>
You need Castor 0.9.3 for the above trick to work.
Thanks,
--Keith
"Kathan, Joe" wrote:
>
> Hi
>
> I am seeking some advice on how to handle the following situation. To
begin
> with, lets assume I have created a class as shown:
>
> public class Thing {
>
> private int size;
>
> public Thing() {
> }
>
> public void setSize(int aSize) {
> size = aSize;
> }
>
> public int getSize() {
> return size;
> }
>
> }
>
> Let's further assume I have this mapping:
>
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
> 1.0//EN"
> "http://castor.exolab.org/mapping.dtd">
>
> <mapping>
> <class name="Thing">
> <map-to xml="thing"/>
> <field name="size"
> type="integer">
> <bind-xml name="size" node="element"/>
> </field>
> </class>
> </mapping>
>
> Lastly, let's assume I have this xml:
>
> <?xml version="1.0"?>
> <thing>
> <size>100</size>
> </thing>
>
> When I unmarshall and then marsall this, everything works fine...I end up
> with a Thing object after unmarshall that has a size of 100, and I end up
> with the xml again after marshalling.
>
> Now for the problem. One of the strengths of XML is that it allows
> decoupling the client from the service that fills the request. The service
> in our example only cares about the size of something. A developer,
however,
> working on the next version of the client wants to add the color, say, to
> the xml for later use by the service. So they start sending xml like this:
>
> <?xml version="1.0"?>
> <thing>
> <color>red</color>
> <size>100</size>
> </thing>
>
> When I run this new XML with the existing map and class, I now get an
> exception that the field color is not specified in the map. Specifically:
> org.xml.sax.SAXException: unable to find FieldDescriptor for 'color' in
> ClassDescriptor of thing{file: [not available]; line: 3; column: 8}
>
> If I had passed this xml through JOX, the other tool I use, it would have
> skipped color and kept on going, making the object as I require. Castor,
by
> throwing the exception (or more correctly, passing the exception up), is
> requiring a tight coupling between the xml and the class. How can I handle
> this without changing the class in any way and still allowing the client
> side developer to add tags as they wish? I haven't found a mapping that
> allows it...and sticking a stylesheet between the client and the service
to
> filter the color tag out is not an option at this time.
>
> Thanks for any suggestions.
>
> > Joe Kathan
> > Medic Computer Systems, LLC
> > <mailto:[EMAIL PROTECTED]>
> > (919)-847-8102 x1862
> > Views expressed by the author do not necessarily represent those of
Medic
> > Computer Systems, LLC management and Board of Directors
> >
> >
>
> -----------------------------------------------------------
> 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