Search code examples
playframework-1.x

invalid characters in JSON message after using await/job in play framework 1.2.5


I am using play framework 1.2.5 jobs - after await, I send a message to the web UI in JSON format. The same JSON logic works fine when not using jobs - however, after using jobs and await, the JSON message appears to contain invalid characters (client side javascript does not recognize it as valid JSON anymore). The browser does not render the garbled/invalid characters - I will try using wireshark and see if I can add more details. Any ideas on what could be causing this and how best to prevent this? Thanks in advance (I'm reasonably sure its my code causing the problem since I can't be the first one doing this). I will also try to test using executors/futures instead of play jobs and see how that goes.

Promise<String> testChk = new TestJobs(testInfo, "validateTest").now(); //TestJobs extends Job<String> & I'm overriding doJobWithResult.  Also, constructor for TestJobs takes two fields (type for testInfo & String)
String testChkResp = await(testChk);
renderJSON(new TestMessage("fail", "failure message"));  //TestMessage class has two String fields and is serializable

Update: I am using gson & JDK1.6

Update It seems that there is a problem with encoding whenever I use play jobs and renderJSON.

TestMessage: (works when not using jobs)

import java.io.Serializable;

public class TestMessage {
    public String status;
    public String response;

    public TestMessage() {
    }

    public TestMessage(String status, String response) {
        this.status = status;
        this.response = response;
    }
}

Update: Even using the following results in utf-8 impact when using while relying on jobs.

RenderJSON("test"); 

Solution

  • I was able to use futures & callables with executors and the same code as mentioned above works (using play 1.2.5). The only difference was that I was not explicitly using play jobs (and hence the issue does not appear to be related to gson).