I am working with REST services and i want to pass an XML-text with a POST request. My server is implemented in JAVA. Let's say that i am sending this XML:
<range>
<higher value="3"></higher>
<lower value="2"></lower>
</range>
As i understand (correct me if i am wrong), the easiest way to convert the XML in the request to a java object, is to define a class with the proper annotations. For example:
@XmlRootElement(name = "range")
public class RangeClass {
@XmlElement (name = "lower")
private int lower;
@XmlElement (name = "higher")
private int higher;
.
.
???
}
And then read it like this:
@POST
@PATH(<somePath>)
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.TEXT_PLAIN)
public String myFun(RangeClass range) {
.
.
.
}
The thing that i am missing (if the other parts are correct) is how to define that i have attributes inside the elements. If i put an '@XmlAttribute' annotation this will refer to an attribute of the root element ('range') and not an attribute of a specific element ('lower' or 'higher').