POJO to XML mapping in Java to avoid breaking XHR
Let's say I have a simple POJO class:
public void Foo {
public int a;
public int b;
public Foo() {
a = 0;
b = 1;
}
}
Is there some library in JAVA which will give me XML like this:
<List>
<a value='0'/>
<b value='1'/>
</List>
I have a XHR service but I have to manually "dump" each member to XML to send it back to the client. It could avoid me some开发者_如何学C trouble if dumping was automated.
Thx.
I'd suggest looking at XStream; it should do what you need. Out of the box, I would expect it to produce something like this from your Foo
class:
<foo>
<a>0</a>
<b>1</b>
</foo>
However you can customize the representation of your class through annotations on your class.
精彩评论