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

Reply via email to