XStream JavaBeanConverter not serializing properties
- by Steve Foster
Hello All,
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng something simple, or not understanding XStream's converter handling well enough.
@XStreamAlias("test")
public class TestObject
{
private String foo;
public String getFoo()
{
return foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
}
public void test() throws Exception
{
XStream x = new XStream(new XppDriver());
x.autodetectAnnotations(true);
x.processAnnotations(TestObject.class);
x.registerConverter(new JavaBeanConverter(x.getMapper()));
TestObject o = new TestObject();
o.setFoo("bar");
String xml = x.toXML(o);
System.out.println(xml);
/*
Expecting...
<test>
<foo>bar</foo>
</test>
But instead getting...
<test>
<foo/>
</test>
*/
}
I tried adding a trace on the TestObject.getFoo() method and it appears it is being called by XStream, but the data isn't being written to the output stream.
After looking at the source for JavaBeanConverter, it looks like my implementation should work, which leads me to believe I haven't configured something correctly during the XStream setup.
Am I just missing something simple?
Thanks!
Edit
Also, if it helps, I'm using the following Maven deps for this...
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.xstream</artifactId>
<version>1.3_3</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.xpp3</artifactId>
<version>1.1.4c_3</version>
</dependency>