Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] How to escape Unicode with JSON.toString()?

Hello fellow Jetty users and developers,

is it please possible to escape UTF-8 characters when using

org.eclipse.jetty.util.ajax.JSON.toString() method?

I understand that it might be an internal library, but until now it
works well for me in a servlet which among other tasks sends push
notifications via FCM (Firebase Cloud Messaging) and ADM (Amazon
Device Messaging).

However my problem with the latter is that ADM does not accept any
UTF-8 chars (in my case Cyrillic) and reproducibly fails with the
cryptic error message:

<SerializationException>
<Message>Could not parse XML</Message>
</SerializationException>

java.lang.IllegalStateException:
unknown char '<'(60) in |||<SerializationException>|  <Message>Could
not parse XML</Message>|</SerializationException>||

So is there maybe some possibility in Jetty 9.4.8.v20171121 to encode the chars?

Here is my Java code:

    // this string is POSTed to ADM server
    public String toAdmBody() {
        Map<String, Object> root  = new HashMap<>();
        Map<String, String> data  = new HashMap<>();
        root.put(KEY_DATA, data);
        data.put(KEY_BODY, mBody);
        // ADM does not accept integers
        data.put(KEY_GID, String.valueOf(mGid));
        // TODO encode utf8 chars
        return JSON.toString(root);
    }

Thank you
Alex


Back to the top