I looked at the string that was being sent and found the culprit: an
embedded LINE SEPARATOR char ('\u2028').
If I strip the character from the string, the problem goes away.
I would greatly appreciate it if someone on the GWT team could verify
that \u2028 is getting properly
escaped for JSON.
Thanks,
Paul
For example, the following two lines in java code:
String helloWorld = "Hello World!";
String helloWorld = \u0025Hello World!\u0025;
are -exactly- the same thing, if for a moment you bear with me and
assume 0025 is the code for the quote character. (I made it up)
And the following code will not compile:
String helloWithQuote = "Jack said, \u0025Hello, World!\u0025";
because it is exactly the same as:
String helloWithQuote = "Jack said, "Hello, World!""; //this is
clearly a java syntax error.
Hence, \u operates at a completely different level compared to \", and
all other backslash escapes.
I'm not sure this is your problem, though. I'm just guessing.
The LINE SEPARATOR character is *not* escaped in the current
GWT marshalling to JSON. That is why the the JSON parsing on
the client is choking on the bad character.
Paul
It should be possible to root through the GWT source to figure that
out, but just as verification exercise, can you check and see what
happends if you actually use \u2028 in your java source? Just to make
sure that the step of parsing the java file itself bombs because e.g.
you saved as UTF-8 but for some reason the gwt compiler is trying to
parse your 2028 as ascii/iso-8859 and thus bollockses it up.
I am not sure where in the javascript the problem is happening. All I
know is that I am
getting an JspException when the object containing the offending
character is unmarshalled
in the client.
Another way of seeing the problem is to add a string to some object
that is to be
sent from server to client and assign it a value with an embedded LINE
SEPARATOR char:
test_val = "This is a test " + Character.toString('\u2028') + " of a
bad char";
Send the object to the client and have a look in firebug at the
response sent.
I do not know what the appropriate JSON escape sequence should be for
such a character, but I
can see that no encoding is taking place in the response sent.
Cheers,
Paul