users@jersey.java.net

Re: [Jersey] when I serve json type, how to add prefix or suffix to http response body?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 05 Jan 2009 13:36:52 +0100

Hi,

Do you want to return JavaScript or JSON? from your expected result it
needs you want to return JavaScript, namely a function that takes as a
parameter some JSON.

Is that correct? If so it is not supported by Jersey and you will need
to write a filter to wrap the JSON output in some JavaScript, see the
recent email thread [1] for hints on how to do this.

Paul.

[1] http://markmail.org/search/?q=list
%3Anet.java.dev.jersey.users#query:list%3Anet.java.dev.jersey.users
+page:1+mid:sk7sb73cfuexkbiv+state:results

On Jan 5, 2009, at 9:53 AM, 유재균 wrote:

>
> hello everybody~
> I'm sorry I can't speak english very well.
>
> Question : when I serve json type, how to add prefix or suffix to
> http response body?
>
> please see the code and result below.
>
> ----------------------------------------------------------------
> source code
> ----------------------------------------------------------------
> public Response returnObject(Object obj) {
> .....................
> return ResponseImpl.ok(obj).type("application/
> json").build();
> }
> ----------------------------------------------------------------
>
>
>
> ----------------------------------------------------------------
> result
> ----------------------------------------------------------------
> {"code":"12312","name":"WT-4G120A"}
> ----------------------------------------------------------------
>
>
>
> ----------------------------------------------------------------
> expected result
> ----------------------------------------------------------------
> js_result({"code":"12312","name":"WT-4G120A"})
> ----------------------------------------------------------------
>
>
> happy new year! thank you.