I'm having issues trying to unmarshall a primitive int within a container class.
The marhsalling works just fine, but when i try to unmarshall the xml, I get an infinite loop and eventually a StackOverFlow error.
I wrote a small test case to help describe the situation. Here it is .....
1. Source ------------------------------------------------------------------------------------------- package castortest;
public class ContainerTestItem {
private ContainerTestSubItem containerTestSubItem; public ContainerTestItem() {
containerTestSubItem = new ContainerTestSubItem();
} public ContainerTestSubItem getContainerTestSubItem() {
return containerTestSubItem;
}public void setContainerTestSubItem(ContainerTestSubItem containerTestSubItem) {
this.containerTestSubItem = containerTestSubItem;
}
}
------------------------------------------------------------------------------------
package castortest;
public class ContainerTestSubItem {
private int name; public int getName() {
return name;
} public void setName(int name) {
this.name = name;
}
}
----------------------------------------------------------------------------------
package castortest;import castortest.ContainerTestItem; import castortest.ContainerTestSubItem; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Marshaller; import org.exolab.castor.xml.Unmarshaller; import org.xml.sax.InputSource;
import java.io.FileReader; import java.io.FileWriter;
public class main {
public static void main(String args[]) {
Mapping mapping = new Mapping();
try {
// 1. Load the mapping information from the file
mapping.loadMapping("container-test-mapping.xml"); //create data
ContainerTestItem cItem = new ContainerTestItem();
ContainerTestSubItem csItem = new ContainerTestSubItem();
csItem.setName(2);
cItem.setContainerTestSubItem(csItem);//marshal the data
Marshaller marshaller = new Marshaller(new FileWriter("items.xml"));
marshaller.setMapping(mapping);
marshaller.marshal(cItem);
//unmarshall data
Unmarshaller unmar = new Unmarshaller(mapping);
cItem = (ContainerTestItem) unmar.unmarshal(new InputSource(new FileReader("items.xml")));
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
------------------------------------------------------------------------------------------
2. mapping file
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="castortest.ContainerTestSubItem" auto-complete="false">
<description>Default mapping for class castortest.ContainerTestSubItem</description>
<map-to xml="container-test-sub-item"/>
<field name="name" type="integer" required="false" direct="false" transient="false">
<bind-xml name="name" node="element"/>
</field>
</class>
<class name="castortest.ContainerTestItem" auto-complete="false">
<description>Default mapping for class castortest.ContainerTestItem</description>
<map-to xml="container-test-item"/>
<field name="containerTestSubItem"
type="castortest.ContainerTestSubItem" required="false"
direct="false" transient="false" container="true">
<bind-xml name="container-test-sub-item" node="element"/>
</field>
</class>
</mapping>
note: the container="true" ---------------------------------------------------------------------------------------------------------
3. Generated xml
<?xml version="1.0" encoding="UTF-8"?> <container-test-item> <name>2</name> </container-test-item>
---------------------------------------------------------------------------------------------------------
when i try and unmarshall the above file, using the main class provided, I get an infinite loop while trying to set the name on the sub item. I have tried to step through code and isolate the problem, but havent had too much luck yet.
Please look at this when you get a chance .... any help would be greatly appreciated.
Thanks
_________________________________________________________________
MSN Messenger with backgrounds, emoticons and more. http://www.msnmessenger-download.com/tracking/cdp_customize
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
