What kind of objects does your list actually hold ? Are there subclasses of Vehicles ? What XML are you actually getting, and what XML artefacts would you like to see produced ?
Cheers Werner On 19.04.2011 13:02, Jose Antonio wrote: > Thank you for your reply. It works fine, but now, I'm having another problem > related to this. > > When I marshall the object, the vehicle tags in the xml file doesn't contain > the xsi:type attribute. For that reason, when I unmarshall the object I get > an error. > > Do you know how can I specify this attribute in the mapping file so that it > appears in the resultant xml file? > > I've tried using the type attribute of <bind-xml> tag but it doesn't work. > > Thank you very much. > > 2011/4/19 吕晓一 <[email protected]> > >> Hi, here is an example. >> >> >> >> <myClass> >> >> <vehiclelist> >> >> <vehicle/> >> >> <vehicle/> >> >> </vehiclelist> >> >> </myClass> >> >> >> >> You should define a Vehicle class and a mapping-file for it, and you should >> include this mapping-file in the main mapping-file >> >> >> >> <include href=”VehicleMap.xml”/> >> >> <class name="your.package.MyClass" auto-complete="true"> >> >> <map-to xml="myClass"/> >> >> <field name="vehicles" type="your.package.Vehicle" >> collection="arraylist"> >> >> <bind-xml name="vehicle” node="element" location="vehiclelist"/> >> >> </field> >> >> </class> >> >> >> >> >> >> >> >> >> >> >> >> *发件人:* Jose Antonio [mailto:[email protected]] >> *发送时间:* 2011年4月19日 15:33 >> *收件人:* [email protected] >> *主题:* [castor-user] Exception while mapping a java.util.List attribute >> >> >> >> Hello, I've got a problem mapping a class whose one of its attributes is a >> java.util.List. I'm getting the following exception: >> >> >> >> Caused by: org.springframework.beans.factory.BeanCreationException: Error >> creating bean with name 'xmlContext' defined in class path resource >> [applicationContext.xml]: Invocation of init method failed; nested exception >> is java.lang.IllegalArgumentException: list is not a valid >> FieldMappingCollectionType >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) >> >> at java.security.AccessController.doPrivileged(Native Method) >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) >> >> at >> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) >> >> at >> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) >> >> at >> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) >> >> at >> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) >> >> at >> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) >> >> at >> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) >> >> ... 154 more >> >> Caused by: java.lang.IllegalArgumentException: list is not a valid >> FieldMappingCollectionType >> >> at >> org.exolab.castor.mapping.xml.types.FieldMappingCollectionType.valueOf(FieldMappingCollectionType.java:249) >> >> at >> org.exolab.castor.xml.XMLMappingLoader.createFieldDesc(XMLMappingLoader.java:625) >> >> at >> org.exolab.castor.mapping.loader.AbstractMappingLoader.createFieldDescriptors(AbstractMappingLoader.java:408) >> >> at >> org.exolab.castor.xml.XMLMappingLoader.createClassDescriptor(XMLMappingLoader.java:231) >> >> at >> org.exolab.castor.mapping.loader.AbstractMappingLoader.createClassDescriptors(AbstractMappingLoader.java:255) >> >> at >> org.exolab.castor.xml.XMLMappingLoader.loadMapping(XMLMappingLoader.java:152) >> >> at >> org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:164) >> >> at >> org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:130) >> >> at org.exolab.castor.xml.XMLContext.addMapping(XMLContext.java:82) >> >> at >> org.castor.spring.xml.XMLContextFactoryBean.afterPropertiesSet(XMLContextFactoryBean.java:121) >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) >> >> at >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) >> >> ... 164 more >> >> >> >> What I am trying to do is: >> >> >> >> I want the java.util.List attribute to be mapped with a diferent name in >> the xml file. For example, if the attribute is: >> >> >> >> private List<Vehicle> vehicles; >> >> >> >> I want this attribute to be mapped with the name "myVehicles" in the xml >> file. >> >> >> >> What I have done in the mapping file is: >> >> >> >> <class name="MyClass" auto-complete="true"> >> >> <map-to xml="myClass"/> >> >> <field name="vehicles"><bind-xml name="myVehicles"/></field> >> >> </class> >> >> >> >> Please, if anyone knows what it is happening, help. >> >> >> >> Thanks in advance >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

