...
One of the coolest thing of REST is that the same resource can be accessed served using multiple Representationsrepresentations. @ProduceMime and @ConsumeMime annotations are used to declare the supported request and response media types.
JAXB support
To accept or return Objects that The request and response can be marshaled /unmarshaled using JAXB, the Objects need and unmarshaled to/from Java object using JAXB. The Java object needs to be marked with @XmlRootElement annotation. For example:
...
Code Block | ||||
---|---|---|---|---|
| ||||
@UriTemplate("/customerservice/") <Customer> <id>123</id> <name>John</name> </Customer> |
To return or accept Object work with collections, you need to define an Object object collection type. For example:
...
Following code returns a Customer Object object that is marshaled to JSON format:
...
Code Block | ||||
---|---|---|---|---|
| ||||
{"Customer ":{"id":"123","name":"john"}}
{code:java}
h3. DOMSource support
You can also receive the request as a DOMSource object or return DOMSource object as response:
{code:java}
@UriTemplate("/bookstore/")
public class BookStore {
@HttpMethod("GET")
@UriTemplate("/customers/{customerId}/")
public javax.xml.transform.dom.DOMSource getCustomer(@UriParam("customerId") String id) {
....
}
}
|
...