Hello Bobby, on client side, there are radical ways. For example, update the list of registered converters at the Engine level: Engine.getInstance().getRegisteredConverters().clear(); Engine.getInstance().registerDefaultConverters(); which is more or less the same as setting the right classpath.
you can also call the ClientResource#toRepresentation(Object, Variant) method in order to generate the Representation using the right MediaType: ClientResource cr = new ClientResource("http://localhost:8182/mybean"); Representation rep = cr.toRepresentation(new MyBean("test"), new Variant(MediaType.APPLICATION_JAVA_OBJECT)); cr.post(rep); Regarding the returned entity, the client can just specify its media type preference: - as a parameter of the ClientResource#post method cr.post(new MyBean("test"), MediaType.APPLICATION_JAVA_OBJECT); - or set at the ClientResource: // Restlet 2.0 and smaller cr.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(MediaType.APPLICATION_JAVA_OBJECT)); // which has been shortcut only for Restlet 2.1 and higher cr.accept(MediaType.APPLICATION_JAVA_OBJECT); As a side note, if you are issuing several requests to the same domain but distinct resources, you can do as follow: // Instantiate a root ClientResource ClientResource crRoot = new ClientResource("http://localhost:8182/"); crRoot.accept(MediaType.APPLICATION_JAVA_OBJECT); // inherits from the preferences of the root ClientResource. ClientResource cr = crRoot.getChild("mybean"); I hope this will help you, Best regards, Thierry Boileau I am using version "restlet-jse-2.0.13" > > I want to do a POST request to my server and use Java serialized objects > for sending and receiving the objects. > > Sample test API is shown below where both PingResponse and PingReqest are > Serializable Java Objects. > public interface IPing { > public static final String URI_PATH = "/ping"; > > // @Post("x-java-serialized-object") > // @Post("application/x-java-serialized-object") > public PingResponse push(PingRequest request); > > } > > The server is configured to use both the xstream and jackson extensions > (Both are JSON) as I have some other APIs that I would like to return the > JacksoneRepresentation for. The jackson extension is first in the classpath > on the server, so the server defaults to using Jackson extension. > > PROBLEM: as below ... > > The problem is related to which convertor gets applied on the client side > for encoding of the PingRequest object (server side convertor selection is > also a problem, but first I want to address client side convertor selection > in this issue) > > If I only have the org.restlet.jar on the client side without any > extensions, then the code works fine as it selects the default convertor > for the Java Serialized objects and the server can handle that. > > If I add the org.restlet.ext.xstream.jar extension on the client side, now > the PingRequest object gets encoded using the Jackson convertor instead of > the default convertor, and the call fails with error below on the server > > "Unable to parse the object with Jackson. > org.codehaus.jackson.map.JsonMappingException: Unrecognized field > "com.test.PingRequest" > > Client gets back error "Unsupported Media Type (415) - Unsupported Media > Type" > > If I change the classpath order on the server side to have the xstream > first before the jackson extension, then the call will work as both sides > are using the jettison encoding instead of the jackson one. > > But, what I really want is a way to specify on the client side and server > side, to use the default convertor, rather than any of the JSON ones for > this API. > > Looking at the code in the "restlet-jse-2.0.13" version, in file > org.restlet.resource.ClientResource.java around line 1632 > LINE 1632 : requestEntity = toRepresentation(args[i], null); > > It looks like if the second parameter was specified as a valid target for > the annotation ("application/x-java-serialized-object"), then the default > convertor would return a score of 1.0 and would get definitely selected > correctly. > > Do you think adding the annotation target makes sense, or is there another > way this can be achieved to solve the problem? > > If you need some test code, please let me know and I will package some > test code to show this issue as well. > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2972982 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2973469