Hi Scott,

Yes, bug 1006 points out inconsistency with introspection as compared
with mapping files. I've already started a patch for bug 1006 and plan
on having it finished for inclusion in the next Castor release
(currently scheduled for Oct 7th).

Thanks,

--keith


Scott Sims wrote:
> 
> Amar,
> 
> Do you have a simple example of this working?  I know Castor "supports"
> lists and arrays in virtually the same way.  However it may not support them
> in the way that David expects.  For example, given the following in Fig 1:
> 
> import java.util.*;
> 
> public class TestObject
> {
>   public TestObject() {}
>   public List getObjects() { return list; }
>   public void setObjects(List list) { this.list = list; }
>   private List list = new ArrayList();
> }
> 
> public class TestObject1
> {
>   public TestObject1() {}
> 
>   // Using int
>   public TestObject1(int i) { this.i = i; }
> 
>   private int i;
>   private int j;
> 
>   public int getI() { return i; }
>   public void setI(int i) { this.i = i; }
> 
>   public int getJ() { return j; }
>   public void setJ(int j) { this.j = j; }
> }
>                        (Fig 1)
> 
> with a mapping of Fig 2:
> 
> <?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="TestObject">
>                 <map-to xml="testObject"/>
>                 <field name="objects"
>                        collection="arraylist"
>                        type="TestObject1">
>                        <bind-xml name="objects"/>
>                 </field>
>         </class>
>         <class name="TestObject1">
>                 <map-to xml="testObject1"/>
>                 <field name="i" type="integer">
>                         <bind-xml node="element"/>
>                 </field>
>                 <field name="j" type="integer">
>                         <bind-xml node="element"/>
>                 </field>
>         </class>
> </mapping>
>                       (Fig 2)
> 
> you may expect to get the following Fig 3:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <testObject>
>     <objects>
>         <testObject1>
>             <i>1</i>
>             <j>0</j>
>         </testObject1>
>         <testObject1>
>             <i>2</i>
>             <j>0</j>
>         </testObject1>
>     </objects>
> </testObject>
>                      (Fig 3)
> 
> Logically, I think this is what many people would expect.  Individual list
> elements are fully represented within the <objects> tag.  However, what
> Castor outputs is Fig 4:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <testObject>
>     <objects>
>         <i>1</i>
>         <j>0</j>
>     </objects>
>     <objects>
>         <i>2</i>
>         <j>0</j>
>     </objects>
> </testObject>
>                      (Fig 4)
> 
> Where the name of the class within the list is lost and the wrapping list
> name is used in its place. Now, if you don't use a mapping file, you get
> something closer to what you may expect (Fig 5):
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <test-object>
>     <objects xsi:type="java:java.util.ArrayList"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
>         <test-object1 j="0" i="1" xsi:type="java:TestObject1"/>
>         <test-object1 j="0" i="2" xsi:type="java:TestObject1"/>
>     </objects>
> </test-object>
>                      (Fig 5)
> 
> Again, the objects within the list are wrapped by the name of the list.  If
> you use a map file you will get the same result whether you choose a List or
> an array as your container.  If you don't use a map file the results are
> slightly different Fig 6:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <test-object>
>     <objects j="0" i="1"/>
>     <objects j="0" i="2"/>
> </test-object>
>                       (Fig 6)
> 
> Notice the array version loses the name of the wrapped class also.
> 
> As far as I know (thanks to Tung Mansfield for the bug # and much of the
> above example) this is a known bug (1006) for Casto XML.  If  you know of a
> way to get the result shown in Fig 3 above please let me know.  The bug is
> still open and I struggling to find a work around.
> 
> Scott
> 
> -----Original Message-----
> From: Amar Mehta [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 24, 2002 12:03 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Does Castor-XML work with lists?
> 
> I know for a fact that Castor supports arrays.  In the mapping file you
> specify for the field element collection="array".  The type for that field
> would be whatever type the list's elements are.  I like returning arrays
> instead of lists just because there is no mistaking the type.
> 
> >From: David Tayouri <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: [EMAIL PROTECTED]
> >Subject: [castor-dev] Does Castor-XML work with lists?
> >Date: Tue, 24 Sep 2002 18:20:35 +0200
> >
> >I tried to marshal to XML a Java object that includes an ArrayList,
> >but only an empty XML was created.
> >Is Castor-XML supposed to support lists?
> >
> >-----------------------------------------------------------
> >If you wish to unsubscribe from this mailing, send mail to
> >[EMAIL PROTECTED] with a subject of:
> >       unsubscribe castor-dev
> 
> _________________________________________________________________
> Join the world�s largest e-mail service with MSN Hotmail.
> http://www.hotmail.com
> 
> -----------------------------------------------------------
> 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