I'm puzzled by this -- I'm having trouble understanding why any of
' < > & =
need to be escaped in a JSON string -- since the string is already in
double-quotation marks, these characters can't affect any surrounding
JSON or JavaScript, right?. Could you explain a bit more about the use
case of embedding in XML that you mentioned? Is there a reason why
Gson's output is intended to work for such a use case without any further
escaping? Why not let those who have such a use case do their own
escaping appropriate to the use case?
On a separate note, I am curious why some whitespace characters are
escaped (e.g. \u2028) but others are not (e.g. \t). If the JSON is
intended just for transmission over the wire, then none of these
characters will be affected; the only characters that ever need to be
escaped are " and \. If the JSON is intended to be handled by editors
or other programs that collapse whitespace, then all whitespace will
need to be escaped. Maybe there is an organizing principle that I'm
missing here?
Perhaps it will help me understand these design choices if you can
describe the set of use cases for which Gson's JSON output is intended.
Thanks!
-- ?!ng