Is there a way to pass a list of elements as a parameter to a method using Jersey?
I have the class Sample
annotated with @XmlRootElement
with the following variables: idUsuario
, x
, and timestamp
.
In my MedicaoResource
class, the method:
@GET
@Produces("text/xml")
public List<Medicao> getMedicoes() {
return new ArrayList<Medicao>(getAllMedicoes());
}
returns something like:
<medicaoes>
<medicao>
<idUsuario>1</idUsuario>
<timestamp>2012-04-16T12:25:00.454-03:00</timestamp>
<x>0.71</x>
</medicao>
<medicao>
<idUsuario>1</idUsuario>
<timestamp>2012-04-16T12:25:00.454-03:00</timestamp>
<x>1.71</x>
</medicao>
</medicaoes>
Now, I would like to do something like this:
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces("text/plain")
public String addMedicoes(ArrayList<Medicao> medicoes) {
for (Medicao medicao : medicoes) {
addMedicao(medicao);
}
return "success";
}
How would I have to write my XML for the method above to work properly? I have tried passing the same XML that the method getMedicoes
returns, but it won't work.