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




Reply via email to