Developer notes written down before they get lost.

Restlet Extension for Piriti
25Mar2010

Restlet is a RESTful Web framework for Java. There’s also a GWT edition available. The Piriti
Restlet extensions is built on top of that edition. Therefore the 2.x version of Restlet is used. There are two
representations available which use the Piriti readers to convert JSON and XML data to your model (POJOs and/or
GXT models).

ClientResourceclientResource=newClientResource("/resource/with/json/representation");clientResource.setOnResponse(newUniform(){@Overridepublicvoidhandle(Requestrequest,Responseresponse){PiritiJsonRepresentation<Book>representation=newPiritiJsonRepresentation<Book>(Book.JSON,response.getEntity());try{// Depending whether there's one book or an array of books// in your JSON dataList<Book>books=representation.getModels();Bookbook=representation.getModel();}catch(IOExceptione){e.printStackTrace();}}});clientResource.get(MediaType.APPLICATION_JSON);

The entity returned by the resource has to be a valid JSON object. In case you want to read a list of books, the
JSON object has to contain one key (name does not matter) with the array of books:

ClientResourceclientResource=newClientResource("/resource/with/xml/representation");clientResource.setOnResponse(newUniform(){@Overridepublicvoidhandle(Requestrequest,Responseresponse){PiritiXmlRepresentation<Book>representation=newPiritiXmlRepresentation<Book>(Book.XML,response.getEntity());try{// Depending whether there's one book element or a list of book// elements in your XML dataList<Book>books=representation.getModels();Bookbook=representation.getModel();}catch(IOExceptione){e.printStackTrace();}}});clientResource.get(MediaType.TEXT_XML);

The entity returned by the resource has to be a valid XML document. In case you want to read a list of books, the
document must contain a list of book elements as direct children of the root element: