Hi Stephane, Mapping an array directly is not possible because of the way Java handles arrays - each array type in Java is a separate class, but it's a synthesized class rather than a real one. Because the class is synthetic there's no way to add information to the class.
It's not too hard to handle this directly, though. If the root object you're marshalling/unmarshalling is an array, just define a normal <mapping> for the item type of the array and a custom <mapping> for the array type using org.jibx.extras.TypedArrayMapper as the marshaller= and unmarshaller=. You can get the factory by passing the item type, rather than the array type. I think unmarshalling should then work automatically. Marshalling is a little more difficult - you have to search through the array returned by the IBindingFactory.getMappedClasses() method to determine the mapping index, then use that index to call the IMarshallingContext.getMarshaller() method. You can then use the returned IMarshaller directly. Let me know if you run into any problems doing this. - Dennis Dennis M. Sosnoski SOA, Web Services, and XML Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-296-6194 - Wellington, NZ +64-4-298-6117 Stephane Elie wrote: > Hi Dennis, > > I have read the tutorials before and they are very clear and well written. > > What I want to do is not in these tutorials though. > > The root of my problem lies in the fact that the <collection> tag has > to be within a <mapping> definition, which is linked to a class. > Basically, I want to map only a MyItem[] java array in the XML file, > not a MyItem, nor a MyClass.MyItem[]. > So when I want to actually do my binding, I do > BindingDirectory.getFactory( MyItem[] ), which I cannot get to work. > > I know how to bind an array within a class, but not an array of > class. Is it possible? > > Thanks, > Stephane > > On 11/9/06, *Dennis Sosnoski* < [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > Hi Stephane, > > The tutorial section on collections gives some examples that should be > relevant: > http://jibx.sourceforge.net/tutorial/binding-collects.html For > what you want, a simple binding like: > > <collection field="list" name="list"> > <structure name="item" type="MyItem"> > <value name="field" field="field"/> > </structure> > </collection> > > should do exactly what you want. > > Had you looked at the binding tutorial? If this isn't clear from the > tutorial, I'd appreciate feedback on how to show it more clearly. > > - Dennis > > Dennis M. Sosnoski > SOA, Web Services, and XML > Training and Consulting > http://www.sosnoski.com - http://www.sosnoski.co.nz > <http://www.sosnoski.co.nz> > Seattle, WA +1-425-296-6194 - Wellington, NZ +64-4-298-6117 > > > > Stephane Elie wrote: > > Hi, > > > > I haven't found a way to map an array directly in the XML file. > > > > I would like to do something like this: > > > > <binding> > > <!-- this works and map a single object in the XML file --> > > <mapping class=" test.MyClass" name="item"> > > <value name="field" field="field" /> > > </mapping> > > > > <!-- I want to do something like this, but it doesn't work... --> > > <collection item-type="test.MyClass" name="list"/> > > </binding> > > > > I want my XML file to look like : > > <list> <!-- I don't care about the name here --> > > <item> > > <field>value1</field> > > </item> > > <item> > > <field>value2</field> > > </item> > > <item> > > <field>value3</field> > > </item> > > </list> > > > > and this maps in a Java array : test.MyClass[] > > > > Anybody knows if this is possible? > > > > Thanks, > > > > Stephane > > > > P.S. > > I can create a wrapper class around the array like this (but it > is not > > practical for me...): > > <binding> > > <mapping class="test.WrapperClass" name="top_level"> > > <collection name="list" field="list"/> > > </mapping> > > </binding> > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, > security? > > Get stuff done quickly with pre-integrated technology to make > your job easier > > Download IBM WebSphere Application Server v.1.0.1 based on > Apache Geronimo > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > jibx-users mailing list > > jibx-users@lists.sourceforge.net > <mailto:jibx-users@lists.sourceforge.net> > > https://lists.sourceforge.net/lists/listinfo/jibx-users > <https://lists.sourceforge.net/lists/listinfo/jibx-users> > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > <mailto:jibx-users@lists.sourceforge.net> > https://lists.sourceforge.net/lists/listinfo/jibx-users > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users