Closed GoogleCodeExporter closed 9 years ago
Original comment by gael.laz...@gmail.com
on 26 Jan 2012 at 6:43
I just fixed the JSONObject.toString() method on trunk, and have deployed a new
0.36-SNAPSHOT version.
Could you please try it and give me some feedback so I could close this issue ?
Thanks :)
Original comment by gael.laz...@gmail.com
on 31 Jan 2012 at 6:52
Thanks for the fix.
I'm terribly sorry to not replying earlier, I was way too busy.
I accidentally found the download link at:
http://code.google.com/p/gwt-test-utils/issues/detail?id=74
So I took the latest available jar file
(gwt-test-utils-0.36-20120205.120430-11.jar) from
http://forge.octo.com/nexus/content/repositories/snapshots/com/octo/gwt/test/gwt
-test-utils/0.36-SNAPSHOT/ and tested this problem.
Just for the record, I needed to add jackson-core-asl-1.9.4.jar to the build
path (downloaded from http://jackson.codehaus.org/).
Now there are other problems than the originally reported problem.
Add the following code to GwtTestSample.java:
@SuppressWarnings("deprecation")
protected static String rowToJson(String[] ro) {
String rowId = "0";
JSONObject jo = new JSONObject();
JSONArray jsonArr = new JSONArray();
JSONValue v=null;
for(int i=0; i < ro.length; i++) {
if (ro[i] != null) {
if (ro[i].startsWith("{")) {
// expected to contain JSON Object
v = JSONParser.parse(ro[i]).isObject();
} else {
v = new JSONString(ro[i]);
}
} else {
System.out.println("### ro[" + i + "] is null!");
}
jsonArr.set(i, v);
}
jo.put("itemIndex", new JSONNumber(0));
jo.put("rowData", jsonArr);
jo.put("identifier", new JSONString(rowId));
String jsonStr = jo.toString();
return jsonStr;
}
Add the following code e.g. at the beginning of OnModuleLoad():
String[] rows = new String[2];
rows[0] = "whatever";
rows[1] = "{text:\"OK\",bgColor:\"ok\",fgColor:\"white\"}";
String str = rowToJson(ro);
System.out.println("rowToJson:");
System.out.println(str);
Add the following to GwtTestSample.gwt.xml:
<!-- Other module inherits -->
<inherits name="com.google.gwt.json.JSON" />
May need a clean build at this point.
Now, run or debug GwtTestSample as "Web Application" (as you debug GWT
projects). In the Console output you will see:
rowToJson:
{"itemIndex":0, "rowData":["whatever",{"text":"OK", "bgColor":"ok",
"fgColor":"white"}], "identifier":"0"}
Based on this we can create a new test in GwtTestSampleTest.java:
@Test
public void testJson() {
String[] ro = new String[2];
ro[0] = "whatever";
ro[1] = "{text:\"OK\",bgColor:\"ok\",fgColor:\"white\"}";
assertEquals("{\"itemIndex\":0, \"rowData\":[\"whatever\",{\"text\":\"OK\", \"bgColor\":\"ok\", \"fgColor\":\"white\"}], \"identifier\":\"0\"}",
GwtTestSample.rowToJson(ro));
}
Then do a Run As -> JUnit test on GwtTestSampleTest.java.
It fails, as rowToJson() running from unit test generates the following output
(instead of the correct output above):
{itemIndex:0.0, rowData:[whatever,{text:OK, bgColor:ok, fgColor:white}],
identifier:0}
Could you please the necessary changes so that this test would pass?
Original comment by vangel.a...@gmail.com
on 11 Feb 2012 at 4:11
Thank you very much for your feedback.
I just deploy a new 0.36-SNAPSHOT which should format JSONObject.toString()
well.
I've also updated the list of thrid party dependencies to include jackson-core
jar : http://code.google.com/p/gwt-test-utils/wiki/HowToUse#Without_Maven
Could you give it another try ?
Original comment by gael.laz...@gmail.com
on 12 Feb 2012 at 2:44
Thanks for the fast turnaround and for the fix.
I tried with gwt-test-utils-0.36-20120213.140641-13.jar and I am happy to
confirm that now it works correctly.
Original comment by vangel.a...@gmail.com
on 14 Feb 2012 at 9:50
Thx !
Original comment by gael.laz...@gmail.com
on 14 Feb 2012 at 9:52
Original issue reported on code.google.com by
vangel.a...@gmail.com
on 25 Jan 2012 at 9:39