|
From: Guilherme G. <ger...@gm...> - 2010-06-28 20:04:43
|
Hello,
Let's say there's a method:
@GET
@Path("/any_path")
@Produces("application/json")
public String getAnyValue();
Should this implementation return a String already converted to a JSON (1)
or the conversion to JSON would be implemented automatically by Resteasy
(2)?
(1) Something along the lines of (all exceptions were omitted):
@GET
@Path("/any_path")
@Produces("application/json")
public String getAnyValue() {
ObjectMapper codec = new ObjectMapper(); // jackson's mapper
ByteArrayOutputStream baos = new ByteArrayOutputStream();
codec.writeValue(baos, "any value");
return new String(baos.toByteArray());
}
(2) Something along the lines of:
@GET
@Path("/any_path")
@Produces("application/json")
public String getAnyValue() {
return "any value"; // the magic is made by Resteasy, just like would be
made
// if an annotated object would be returned.
}
If approach (2) is to be ok, I run into trouble: When I create a client
using the Resteasy Client Framework, both client and server communicate
perfectly. However, if I use another client, e.g. implemented using
org.apache.commons.httpclient.HttpClient, this client is unable to parse the
response into a JSON. Also, by debugging the response, I can see that the
supposed automatic conversion from String to JSON is not working (the same
String returned is received by the client, when the correct -- I think --
would be to put it between double quotes: this is how a String is
represented in JSON, right?).
Thank you very much (and congratulations for such wonderful tool!)
--
Guilherme
msn: gui...@ho...
homepage: http://sites.google.com/site/germoglio/
|