1

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?

timss
  • 9,344
  • 3
  • 31
  • 54
zohar
  • 2,188
  • 13
  • 39
  • 75
  • 2
    Why do you expect a semicolon? In Javascript the semicolon character is optional in most situations. – andyb May 02 '13 at 15:18
  • Ho, I didn't knew that it is optional. What are the situations where it is mandatory? – zohar May 04 '13 at 15:05
  • The process is called Automatic Semicolon Insertion (ASI) and is well covered on http://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi which summarises the points much better than I could write in a comment. – andyb May 07 '13 at 08:15

1 Answers1

1

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)?

Community
  • 1
  • 1
andyb
  • 42,062
  • 11
  • 113
  • 146