users@jersey.java.net

Re: [Jersey] Controlling name of outermost tag when returning a list?

From: Moises Lejter <moilejter_at_gmail.com>
Date: Tue, 6 Oct 2009 14:44:28 -0500

Hmm - I may be missing something....With the code below:
- /list/asChild returns
  <items/>
  without showing the contents of the array
- /list/asWrapper returns
  <items>
    <values>
      <id>0</id>
    </values>
  </items>
 and (a) I get two wrappers around my list, and (b) I lose the <item> tag
(?!)

I suspect it may be something really simple - but I don't see it :-(. Help?

Moises

---cut here---

@Path("/list")
public class Lister {
  @GET @Path("/asChild")
  public ValueList valuesAsChild() {
    return
      new ValueList( new Value() );
  }
  @GET @Path("/asWrapper")
  public ListWrapper valuesAsWrapper() {
    return
      new ListWrapper( new Value() );
  }
  @XmlRootElement(name="items")
  static public class ValueList extends ArrayList<Value>
    implements List<Value> {
    ValueList() {}
    ValueList( Value value ) {
      add(value);
    }
  }
  @XmlRootElement(name="items")
  static public class ListWrapper {
    public List<Value> values = new ArrayList<Value>();
    ListWrapper() {}
    ListWrapper( Value value ) {
      values.add(value);
    }
  }
  @XmlRootElement(name="item")
  static public class Value {
    public int id;
  }
}