You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Thorsten Scherler <sc...@gmail.com> on 2011/04/12 12:19:08 UTC
c3 and JSON
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/
--
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/