Hi,


I downloaded Castor XML 0.9.5.3 rc1 to try out the built-in support for java.util.Map. Wrote a simple test program. The following is the output -

The class -

public class SimpleBean
{
 private Map map;

 public Map getMap()
 {
   return map;
 }

 public void setMap(Map map)
 {
   this.map = map;
 }
}


The mapping -


<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="tavant.SimpleBean" >
<description>Default mapping for class tavant.SimpleBean</description>
<map-to xml="simple-bean"/>
<field name="map" required="false" direct="false" transient="false" >
<bind-xml name="map" node="element"/>
</field>
</class>
</mapping>


The Obect - > XML transformation gives me -


<?xml version="1.0" encoding="UTF-8"?>
<simple-bean>
<map xsi:type="java:org.exolab.castor.mapping.MapItem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<key xsi:type="java:java.lang.String">key1</key>
<value xsi:type="java:java.lang.String">value</value>
</map>
<map xsi:type="java:org.exolab.castor.mapping.MapItem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<key xsi:type="java:java.lang.String">key</key>
<value xsi:type="java:java.lang.String">value</value>
</map>
</simple-bean>


But the XML -> Object, with the above XML as input throws the following error. Ideally I would like not to make any assumptions about the types of the keys and values of the map entries.

org.xml.sax.SAXException: unable to add 'map' to <simple-bean> due to the following exception:
>>>--- Begin Exception ---<<<
java.lang.IllegalArgumentException: Type conversion error: could not set value of map(java.util.Map) with value of type org.exolab.castor.mapping.MapItem
at org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:474)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:893)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:960)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:583)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:491)
at tavant.CastorExperiments.main(CastorExperiments.java:67)
>>>---- End Exception ----<<<


at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:926)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:960)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:583)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:491)
at tavant.CastorExperiments.main(CastorExperiments.java:67)


Thanks,
Radhakrishnan

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev




Reply via email to