开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜