users@jersey.java.net

Re: [Jersey] JSONObjectProvider doesn't check media type

From: Bruno Vernay <brunovern.a_at_gmail.com>
Date: Thu, 11 Jun 2009 11:22:03 +0200

There could be a compile time error, but the code looks wrong since
you explicitly create JSON and declare that it is XML.

Bruno


On Thu, Jun 11, 2009 at 10:46 AM, Martin Probst<mail_at_martin-probst.com> wrote:
> Hi,
>
> I'm not sure if this is actually a bug, but JSONObjectProvider does
> not actually check the media type in its "isWritable" method.
>
> Thus you can have this code:
>
> @Path("/hello")
> class Foo {
>  @GET
>  @Produces("application/xml")
>  public JSONObject get() {
>    JSONObject result = new JSONObject():
>    result.put("hello", "world");
>    return result;
>  }
> }
>
> And then do this:
>
> curl -i -H "Accept: application/xml" http://localhost:9999/hello
>
> And you'll get something like this:
>
> HTTP/1.1 200 OK
> Content-Type: application/xml
> Transfer-Encoding: chunked
> Server: Jetty(6.1.17)
>
> {"hello":"world"}
>
> That seems a bit unfortunate. I was actually trying to write a
> JSON->XML converter as I find that a bit cleaner than XML->JSON (you
> don't loose type information like what field is an integer, and JSON's
> object model is a better fit for Java object structures).
>
> Is this a bug? At least, Jersey produces content that is obviously of
> the wrong media type.
>
> Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
Bruno VERNAY