Hi, I wanted to add those information. It seems that in fact, when I used the mapping file I wrote or the one generated by raccoon, it does not work: in my vector I received an AnyNode instead of the correct element.
---------------------------------------------- . Unmarshaller: (without a mapping file) ---------------------------------------------- - myString = un message - myVector : --- type=class java.lang.Integer val=2 --- type=class java.lang.String val=toto ---------------------------------------------- ---------------------------------------------- . Unmarshaller: (using the mapping file) ---------------------------------------------- - myString = un message - myVector : --- BUG type=class org.exolab.castor.types.AnyNode val=<Objects>2</Objects> --- BUG type=class org.exolab.castor.types.AnyNode val=<Objects>toto</Objects> Because I do not know how to convert a AnyNode to the good values, I would REALLY appreciate help on this subject. I would like to get type=class java.lang.Integer val=2 from the AnyNode. Thanks, gregori Gregori Faroux wrote: > Hi, > > I am using the version castor-0.9.3.9. (last released version). > > And here are the two XML files generated. The first one is when I do > not used the mapping file, the second one is the one I used with the > mapping. > > I will try the CVS version ... > > Thanks, > > gregori > > > > . The xml file looks like: (without the mapping file) > ---------------------------------------------- > > <?xml version="1.0"?> > > <my-bean> > <my-vector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:type="java:java.lang.Integer">2 > </my-vector> > <my-vector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:type="java:java.lang.String">toto > </my-vector> > <my-vector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:type="java:castorvalidation.MyBean"> > <my-vector xsi:type="java:java.lang.Integer">333 > </my-vector> > <my-vector xsi:type="java:java.lang.String">inside vector of beanInside > </my-vector> > <my-string>interieur > </my-string> > </my-vector> > <my-string>un message > </my-string> > </my-bean> > ---------------------------------------------- > . Unmarshaller: > ---------------------------------------------- > - myString = un message > - myVector : > --- 2 > --- toto > --- _myString: interieur vec elm(0)= 333 vec elm(1)= inside vector of > beanInside > ---------------------------------------------- > . Castor Test: > . MAPPING USED > ---------------------------------------------- > > . The xml file looks like: (with the mapping file) > ---------------------------------------------- > > <?xml version="1.0"?> > > <ma-classe> > <ma-chaine>un message > </ma-chaine> > <mon-vecteur>2 > </mon-vecteur> > <mon-vecteur>toto > </mon-vecteur> > <mon-vecteur xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:type="java:castorvalidation.MyBean"> > <ma-chaine>interieur > </ma-chaine> > <mon-vecteur>333 > </mon-vecteur> > <mon-vecteur>inside vector of beanInside > </mon-vecteur> > </mon-vecteur> > </ma-classe> > ---------------------------------------------- > . Unmarshaller: > ---------------------------------------------- > - myString = un message > - myVector : > --- <mon-vecteur>2</mon-vecteur> > --- <mon-vecteur>toto</mon-vecteur> > --- _myString: interieur vec elm(0)= <mon-vecteur>333</mon-vecteur> > vec elm(1)= <mon-vecteur>inside vector of beanInside</mon-vecteur> > ---------------------------------------------- > > > > Keith Visco wrote: > >> Which version of Castor are you using? Can you try this with the CVS >> version? >> >> Also please include the XML files that were created during marshalling. >> >> Thanks, >> >> --Keith >> >> Gregori Faroux wrote: >> >>> Hi, >>> >>> I looked in the archive and did not find a solution to my problem. I >>> have a simple bean with 2 fields: one is a String, one is a Vector. >>> Then I create an instance of the bean. >>> Then I set the String. >>> I add in the vector an int. >>> >>> If I use marshall and unmarshall WITHOUT specifing a mapping file, then >>> everything is fine. >>> But, when I use marshall and unmarshall WITH a mapping file, then the >>> bean inside the vector is NOT unmarshall correctly. The value inside >>> the >>> Vector is a String with tags instead of being a simple int. >>> >>> The mapping file I used is this one: (I convert English names to French >>> one). >>> <mapping> >>> <class name="castorvalidation.MyBean"> >>> <map-to xml="ma-classe"/> >>> <field name="myString" type="java.lang.String"> >>> <bind-xml name="ma-chaine" node="element"/> >>> </field> >>> <field name="myVector" collection="vector"> >>> <bind-xml name="mon-vecteur"/> >>> </field> >>> </class> >>> </mapping> >>> >>> Here is the result using Unmarshaller without mapping: (after of >>> course, >>> I used marshall without mapping) >>> - myString = un message >>> - myVector : >>> --- 2 >>> >>> Here is the result using Unmarshaller with mapping (after of course, I >>> used marshall with mapping) >>> - myString = un message >>> - myVector : >>> --- <mon-vecteur>2</mon-vecteur> >>> >>> I do not know what I do wrong or if it's a bug, but I do not think it's >>> normal to have the tag "<mon-vecteur>2</mon-vecteur>" instead of an >>> int !? >>> >>> In the rest of the email you will find the code. >>> >>> Thank you for your time and hopefully someone will guide me, >>> >>> Gregori >>> >>> ------ Mybean.java ------------ >>> package castorvalidation; >>> import java.util.Vector; >>> public class MyBean >>> { >>> private String _myString; >>> private Vector _myVector; >>> >>> public void setMyString(String aString) { _myString = aString; } >>> public String getMyString() { return(_myString); } >>> public void setMyVector(Vector aVector) { _myVector = aVector; } >>> public Vector getMyVector() { return(_myVector); } >>> >>> public MyBean(){} >>> >>> public String toString() >>> { >>> StringBuffer res = new StringBuffer(); >>> res.append(" _myString: "); >>> res.append(_myString); >>> for (int i = 0; i < _myVector.size(); i++) >>> { >>> res.append(" vec elm("); >>> res.append(i); >>> res.append(")= "); >>> res.append(_myVector.elementAt(i).toString()); >>> } >>> return(res.toString()); >>> } >>> } >>> >>> ---- the code to populate the bean ---------------- >>> MyBean bean = new MyBean(); >>> Vector vec = new Vector(); >>> vec.add(new Integer(2)); >>> bean.setMyString("un message"); >>> bean.setMyVector(vec); >>> runMarshall(bean); >>> runUnMarshall(); >>> >>> ---------- methods used to marshall and unmarshall ---------- >>> private void runMarshall(MyBean bean) >>> { >>> try >>> { >>> FileWriter writer = new FileWriter("bean.xml"); >>> Marshaller marshaller = new Marshaller(writer); >>> Mapping mapping = new Mapping(); >>> mapping.loadMapping("mapping.xml"); >>> marshaller.setMapping( mapping ); >>> marshaller.marshal(bean); >>> writer.close(); >>> } catch (Exception e) >>> { >>> e.printStackTrace(); >>> } >>> } >>> >>> /** >>> * runUnMarshall() >>> */ >>> private void runUnMarshall() >>> { >>> try >>> { >>> Unmarshaller unmarshaller = new Unmarshaller(MyBean.class); >>> Mapping mapping = new Mapping(); >>> mapping.loadMapping("mapping.xml"); >>> unmarshaller.setMapping( mapping ); >>> MyBean beanRead = (MyBean) unmarshaller.unmarshal(new >>> FileReader("bean.xml")); >>> System.err.println("- myString = " + beanRead.getMyString()); >>> System.err.println("- myVector : "); >>> Vector vecRead = beanRead.getMyVector(); >>> if (vecRead != null) >>> { >>> for (int i = 0; i < vecRead.size(); i++) >>> { >>> System.err.println("--- " + vecRead.elementAt(i).toString()); >>> } >>> } >>> } catch (Exception e) >>> { >>> e.printStackTrace(); >>> } >>> } >>> >>> ----------------------------------------------------------- >>> 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
