Using Betwixt v0.8, I am having issues trying trying to write and then
read a xml file that has a map that contains key value pairs where the
value contains a a list. The writing of the xml from the bean works
fine. However, the reading of the xml calls the adder but passes an
empty list.
Generated XML:
<example-bean>
<complex-mappings>
<entry>
<key>k1</key>
<value>
<string>s1</string>
<string>s2</string>
<string>s3</string>
</value>
</entry>
</complex-mappings>
</example-bean>
Bean class:
package test;
import ...;
public class ExampleBean {
private Map complexMappings = new HashMap();
public ExampleBean() {
}
public void addComplexMapping(String key, ArrayList values) {
complexMappings.put(key, values);
}
public Map getComplexMappings() {
return complexMappings;
}
}
Driver Class:
package test;
import ...;
public class BetwixtMule {
private static final Log log = LogFactory.getLog(BetwixtMule.class);
private ExampleBean eb;
public BetwixtMule() {
eb = new ExampleBean();
eb.addComplexMapping("k1", new ArrayList(Arrays.asList(new
String[] {"s1", "s2", "s3"})));
}
public static void main(String[] args) {
BetwixtMule betwixtMule = new BetwixtMule();
betwixtMule.testFileWriter();
betwixtMule.testBeanReader();
}
public void testBeanReader() {
BeanReader br = new BeanReader();
//br.getBindingConfiguration().setMapIDs(false);
br.getXMLIntrospector().getConfiguration().setAttributeNameMapper(new
HyphenatedNameMapper());
br.getXMLIntrospector().getConfiguration().setElementNameMapper(new
HyphenatedNameMapper());
try {
br.registerBeanClass(ExampleBean.class);
} catch (IntrospectionException e) {
e.printStackTrace();
}
ExampleBean fromFile = null;
try {
fromFile = (ExampleBean) br.parse(new File("eb.xml"));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
log.debug(fromFile);
}
public void testFileWriter() {
// Open File Writer
Writer ow = null;
try {
ow = new FileWriter("eb.xml");
} catch (IOException e) {
// TODO
}
BeanWriter bw = new BeanWriter(ow);
bw.setEndOfLine("\r\n");
bw.setIndent("\t");
bw.enablePrettyPrint();
bw.getBindingConfiguration().setMapIDs(false);
bw.getXMLIntrospector().getConfiguration().setAttributeNameMapper(new
HyphenatedNameMapper());
bw.getXMLIntrospector().getConfiguration().setElementNameMapper(new
HyphenatedNameMapper());
try {
bw.write(eb);
} catch (SAXException e) {
// TODO
} catch (IntrospectionException e) {
// TODO
} catch (IOException e) {
// TODO
}
// close FileWriter
try {
ow.close();
} catch (IOException e) {
// TODO
}
}
}
Thanks,
-T