tags:

views:

9

answers:

1

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 trouble if dumping was automated.

Thx.

A: 

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.

Craig Trader
Thank you, this is exactly what I was looking for.
code-gijoe