Hi Ruben,

Just use the ObjectRepresentation directly like this:

        Response res = client.handle(req);
        ObjectRepresentation<Item> obj = new    
ObjectRepresentation<Item>(res.getEntity());
        Item item = obj.getObject();

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 

-----Message d'origine-----
De : Ruben Jenster [mailto:[email protected]] 
Envoye : mardi 27 janvier 2009 16:37
A : [email protected]
Objet : passing java objects

Hi,

what is the preferred way of passing a java object from server to client and 
vice versa? Since the getEntityAsObject() is deprecated
how can an object be deserialized on the client side?
e.g.: 

##################### CLIENT            
req.getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JAVA_OBJECT));

Response res = client.handle(req);
// how to get the Item object from the response
####################

#################### SERVER Ressource.represent(Variant variant)
if(MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
  Item item = new Item("object","APPLICATION_JAVA_OBJECT presentation");
                ObjectRepresentation<Item> obj = new 
ObjectRepresentation<Item>(item);
                return obj;
}
###################

Item is a simple class with two string attributes. 
I read some old posts in the list recommending serializing/deserializing 
objects with libraries like XStream or Simple to XML/JSON.
Is this the recommended way? Should I request the XML/JSON MediaType then 
instead of APPLICATION_JAVA_OBJECT?

Regards,
Ruben

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1059265

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1060501

Reply via email to