views:

212

answers:

1

I have been playing with the source code available from the following tutorial.

The GWT/GAE application works in development mode, however when its deployed, the server always returns the response in the JSON format.

I am using the Restlet 2.0 Testing jars, and have also included the dependent libraries.

thank you

A: 

Two things to consider:

Editions

You need to use the GAE edition of Restlet for the server-side app, and the GWT for the client-side app. Neither will suffice for both. For this reason, the two apps are separate projects in the tutorial archive. So make sure you're using the appropriate edition for each side.

Object/Representation Conversion/Serialization and Extensions

I believe that with Restlet 2.0, when a class method annotated with an HTTP method returns a Java object, and doesn't specify how it should be serialized -- converted to a representation -- then Restlet will defer to whichever Restlet extensions are in the classpath which implement this.

In the tutorial, the server-side app includes this jar: "org.restlet.ext.jackson: Jackson extension used to generate JSON representations of the contact resource" -- which I believe is the reason that the response is JSON; the framework is deferring to the extension, which is converting the object into a JSON representation.

Therefore, if, for example, you wanted the framework to automatically serialize your objects into XML, you could remove the Jackson extension JAR from the classpath, and instead include the XStream extension. I believe that would cause the framework to serialize the objects as XML.

The wiki page for ConverterService lists the various conversions which the framework supports, and which modules enable them.

HTH!

Avi Flax
I have been using the right editions.I was thinking that the client sets in the HTTP header what formats it accepts as a return type, and the framework on the server side would transparently return the correct type. Is this right? It seems like that form the above mentioned tutorial.
nick
Yeah, that makes sense. I do think that which extensions are in the classpath does determine which formats the converter service can provide.
Avi Flax