Hello, Just a few words to complete Jonathan's responce.
The next question is "how can I request this specific representation?". Let's say that you define the URI of your User resource like this => http://my.company.org/users/<id>. On the client side, if you have a full control of the HTTP request, you can set the requested URI with http://my.company.org/users/<id> and set the ACCEPT header with the right media-type. If not, for example with your favorite browser, there is one solution based on the Tunnel service [1]. If the Tunnel service is running on server side (e.g. in an Aplication), you can rely on the "mediaTypeParameter". It just says that if your browser requests for "http://my.company.org/users/<id>?media=application/x-java-serialized-object" then the Tunnel Filter updates the request on fly by replacing the media-types preferences sent by the browser with the single preference "application/x-java-serialized-object". Then the Resource will return the right representation. This solution has another effect : it complies with the rule saying that every Representation is a Resource, and thus is identified by its own URI(s). best regards, Thierry Boileau [1] http://www.restlet.org/documentation/1.0/api/org/restlet/service/TunnelService.html On Fri, Mar 14, 2008 at 10:43 PM, Jonathan Hall <[EMAIL PROTECTED]> wrote: > Hi Justin, > > If I understand you, you want to return html,text and an object for a > resource? > Simplest form > > public class MyResource extends Resource { > public MyResource(Context context, Request request, Response response) { > super(context, request, response); > getVariants().add(new Variant(MediaType.APPLICATION_JAVA_OBJECT)); > getVariants().add(new Variant(MediaType.TEXT_PLAIN)); > getVariants().add(new Variant(MediaType.TEXT_HTML)); > > } > > @Override > public Representation getRepresentation(Variant variant) { > Representation rep = null; > if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) { > rep = StringRep... > } > else if (MediaType.TEXT_HTML.equals(variant.getMediaType())) { > rep = Freemarker... > } > else if > (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) { > rep = ObjectRepresenation( YOUR_SERIALIZED_OBJECT ); > } > > return rep; > } > } > > Your client sending: > Accept: application/x-java-serialized-object > > works fine on 1.1 snapshot, sorry I dont have a test setup for 1.0.8. > > > jon > > > > Dustin N. Jenkins wrote: > > Hi all, > > > > This could be a REST understanding problem in general. I'm using JDK > > 1.5.10 with Restlet 1.0.8. > > > > I have a resource that accepts GET requests for a User. The HTML > > representation will return a FreeMarker page, and the Text version > > will just return a String representation of the User. Simple and lovely. > > > > I also want to be able to ask for the User object too, and I think > > that the ObjectRepresentation class is used for that. How do I > > specify that from the Resource though? I thought of narrowing down > > the ClientInfo's accepted MediaTypes to just > > 'x-java-serialized-object' and checking for that in the > > getRepresentation() method of the Resource, but it won't accept > > requests with just that MediaType to choose from. > > > > Any ideas of how to just return the Object? It seems like just > > another representation, but I don't think I should have to create > > another Resource as it's essentially doing the same thing as the HTML > > and Textual representations are doing. > > > > Thanks, > > Dustin > > > > > > > >

