Reputation: 2378
The result of JSONWithPadding is missing the semicolon in the end:
JSONWithPadding jsonWithPadding = new JSONWithPadding({"key":"value"}, "cb");
return Response.status(200).entity(jsonWithPadding).build();
Expected:
cb({"key":"value"}); --> with semicolon
Actual:
cb({"key":"value"}) --> without semicolon
Any ideas?
Upvotes: 1
Views: 614
Reputation: 43823
The semicolon is not missing, it is optional in (this example and) most situations. So the JSONWithPadding
class is working correctly.
The ECMAScript Language Specification defines 7.9.1 Rules of Automatic Semicolon Insertion, summarised from JavaScript and Semicolons as
Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons
This is also well covered at What are the rules for JavaScript's automatic semicolon insertion (ASI)?
Upvotes: 1