Steve Chambers Steve Chambers - 29 days ago 14
Java Question

Why is a JSON response wrapped in a "_jqjsp" outer element?

I'm trying to reproduce some JSON using Spring MVC and Java. The JSON looks like this:

_jqjsp({
"hits":3869,
"highlight":{
"include_matches":false,
"markup_items":false
},
... (lots more) ...
})


Which Java object type would represent the outer element
_jqjsp
and what is it for?

Answer

There is no Java object which represents this construct. Generate the JSON (which is a valid subset of JavaScript object literals) and then wrap it in the "correct" text.

See JSONP as for when this form is generated and how it is consumed:

In the JSONP usage pattern, the URL request pointed to by the <script>'s src attribute returns JSON data, with a function call wrapped around it. In this way, a function that's already defined in the JavaScript environment can manipulate the JSON data. A JSONP payload might look like this:

functionCall({"Name": "Foo", "Id": 1234, "Rank": 7});

While it might not be JSONP per se, depending upon how/where the blocks are generated, the same rules above apply: the output represents JavaScript code that can be executed directly.