hzpz
hzpz

Reputation: 7911

JSONArray not properly working with gwt-test-utils

The following code

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONString;

[...]

JsArrayMixed jsArray = JavaScriptObject.createArray().cast();
jsArray.push("something");    
JSONArray jsonArray = new JSONArray(jsArray);    
System.out.println(jsonArray.size());

will print "0" instead of the expected "1" when run with gwt-test-utils. Looking at the JSONArrayPatcher in gwt-test-utils it seems that the value given to the constructor is completely ignored.

Is there a way to make those lines print "1"? Maybe there is a way to patch the constructor of JSONArray?

Upvotes: 0

Views: 131

Answers (1)

mico
mico

Reputation: 12748

JSONArray has nothing to do with JsArrayMixed. JSONArray is org.json.JSONArray and JsArrayMixed is gwt client object of type com.google.gwt.core.client.JsArrayMixed. These are so completedly from different class hierarchy, that they don't just understand each other.

JSONArray maybe works if you construct it with JSONObject instance or another JSONArray.

You have to invent another way to construct your mixed object.


My sources:

[1] http://www.json.org/javadoc/org/json/JSONArray.html
[2] http://srcrr.com/java/google/gwt/2.2/reference/com/google/gwt/core/client/JsArrayMixed.html

Upvotes: 0

Related Questions