Open vivek-dhayalan opened 8 years ago
Hello,
first of all, the main issue is that Jackson can't serialize the JSONObject
instance, because JSONObject
has no properties.
Actually, if you use JSONObject, you should rely on the org.restlet.ext.json extension only.
That is to say, remove the org.restlet.ext.jackson
extension from your classpath, and add the org.restlet.ext.json
.
You can then write this code:
ClientResource cr = new ClientResource("127.0.0.1:8080/api/devices");
Representation response = cr.put(putBody);
Or even simpler:
ClientResource cr = new ClientResource("127.0.0.1:8080/api/devices");
JSONbject response = cr.put(putBody, JSONObject.class);
If you really prefer using Jackson, remove the dependency to org.json and use beans, or Map.
Then, I notice the following points:
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
Could you tell us why you register the Jackson converter manually? If the org.restlet.ext.jackson
extension is in the classpath, the registration is automatic, unless you are in a very specific case (e.g.: android).
cr.getRequest().setEntity(cr.toRepresentation(putBody));
You should remove this line, since you set the entity when sending the put request: cr.put(putBody)
cr.getResponse().getStatus()
You can shorten this to cr.getStatus()
The following is the data that I got from the logs:
The following is the error message that I have got:
I think need to upgrade to jackson-databind as per the following bug: https://github.com/FasterXML/jackson-databind/issues/539