|
From: Morch, H. <hol...@na...> - 2011-09-09 06:46:57
|
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.
|