|
From: Jeff S. <je...@in...> - 2011-09-09 11:51:50
|
To emphasize this point, Resteasy is lying:
@Produces(MediaType.APPLICATION_JSON)
@GET
public String getSomething() { return "foo"; }
I would expect that Resteasy should *produce JSON*. But it does not -
it produces plaintext that doesn't parse in any browser or JSON
mapper.
We can argue about whether or not "foo" (with quotes) is a proper JSON
document, but it really doesn't matter. Unambiguously, foo (without
quotes) is not. The browser understands "foo" (with quotes). Jackson
(and presumably other ObjectMapper-type tools) understands "foo" (with
quotes). No software understands foo (without quotes). Resteasy's
behavior is annoying and broken.
Jeff
On Thu, Sep 8, 2011 at 11:46 PM, Morch, Holger <hol...@na...> wrote:
> Hi again,
>
>
>
> I think returning a valid json string in the method is not a good
> resolution. Separating the creation of the content from the marshaling is a
> quit good idea. Returning JSON in the method would break this. What if I
> want to support different content types depending on the accept header?
>
>
>
> e.g.
>
> @GET
>
> @Produces({"application/json","text/plain"})
>
> String get() {
>
>
>
> return "Hello World";
>
> }
>
>
>
> If someone want just the string, he can send "Accept text/plain" and gets
> "Hello World" (without the quotes). But if I want to eval the result with a
> JavaScript processor e.g. in a browser, I want something which the browser
> can handle.
>
> Jslint may be a reference, but I ran three short tests with Firefox:
>
> - eval("Hello World "); --> SyntaxError
>
> - eval("\"Hello World\""); --> Works: "Hello World"
>
> - eval("\"Hello World\""); --> Works too: "Hello World"
>
> Note: All three versions fail on Jslint.
>
> So if someone sends "Accept application/json" a JSON marshaller like Jackson
> can produce either ""Hello World"" or "{"Hello World"}" and this can be run
> with eval.
>
>
>
> Just my two cents.
>
>
>
> Kind regards,
>
> Holger
>
>
>
> ________________________________
> The information contained in this communication may be CONFIDENTIAL and is
> intended only for the use of the recipient(s) named above. If you are not
> the intended recipient, you are hereby notified that any dissemination,
> distribution, or copying of this communication, or any of its contents, is
> strictly prohibited. If you have received this communication in error,
> please notify the sender and delete/destroy the original message and any
> copy of it from your computer or paper files.
>
> ------------------------------------------------------------------------------
> Why Cloud-Based Security and Archiving Make Sense
> Osterman Research conducted this study that outlines how and why cloud
> computing security and archiving is rapidly being adopted across the IT
> space for its ease of implementation, lower cost, and increased
> reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>
>
|