I’m a beginner with JAX RS architecture. I’ve made a simple class like this:
@XmlRootElement
public class DatoBase
{
private int _id;
private String _name;
private int[] _listId;
//...here all get and set methods
}
This class, as you can see has an array (_listId), correctly initialized.
I’ve made my web services, that correctly istantiate and POST a new element of DatoBase, and I’ve made a method to GET this element, that is:
@GET
@Produces("application/json")
@Path("{id}")
public DatoBase GetDato(@PathParam("id") int dId)
{
return dati.get(dId);
}
where dati is declared as:
private TreeMap<Integer,DatoBase> dati = new TreeMap<Integer,DatoBase>();
but when I try to get the element i’ve already posted, i see this structure:
{"id":"0","name":"Dato10"}
I can’t see my _listId structure (initialized with 3 elements) in this output.
I expected an output like this:
{"id":"0","name":"Dato10","listId":[...]}
Could anyone help me or tell me why?
Thank you
You should annotate your array with
@XmlElementWrapper.See here for further reference.