Am 12.04.2011 13:42, schrieb Thorsten Scherler:
Hi all,
as I mentioned in another mail I am ATM developing a prototype based on
c3. In another recent project we worked with jersey [1], which is the
reference implementation for JAX-RS (JSR 311).
Our c3 prototype will expose a couple of REST services and looking at
the c3 sources I have not found any references to return a JSONObject
like follows in our REST services.
JSONObject object = JSONObject.fromObject(answerBean);
return object.toString();
where in c3 I do:
return new URLResponse("servlet:/controller/screen", data);
I looked at the URLResponse and on some other classes that implement
RestResponse. In my understanding I need to create a JsonResponse which
would do something like:
JSONObject object = JSONObject.fromObject(answerBean);
return new JsonResponse(object);
and in the JsonResponse
public class JsonResponse implements RestResponse{
execute(...){
IOUtils.write(data.toString(), outputStream);
...
}
Well I did it and it worked very nicely. :)
I needed to add
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
to my POM, though.
Is this from general interest and should I commit the JsonResponse into
the package org.apache.cocoon.rest.controller.response?
salu2
[1] http://jersey.java.net/
I think this is very nice and great addition.
I have to admit that I'm no up-to-date with the current codebase but
your approach sounds very reasonable.
However they are also other frameworks/libraries for handling JSON (eg
http://jackson.codehaus.org/) and it would be very nice if we could
allow the users to choose which one to use.
Not sure how we could/shoulfd go about that tho.
Just an observation... :/
Steven