In GWT, I have a JsArray<JavaScriptObject> in my code. It's more or less a list of JSON objects, but its type is JsArray<JavaScriptObject>. It basically has to be in this format, because I pass it as a parameter to some external JavaScript code using JSNI. Trouble is, I also want this value to be used by Java code. In Java, I'd prefer to deal with an object of type List<JSONObject>. I haven't really found a good way to convert between these two things, though. The best I've been able to do is a linear walk through the array to build the new type I want:
public List<JSONObject> getData() {
LinkedList<JSONObject> list = new LinkedList<JSONObject>();
for (int i = 0; i < data.length(); ++i) {
list.add(new JSONObject(data.get(i)));
}
return list;
}
Am I horribly out of luck? Or is there a nice fast way to get between these two types?
(Returning a JSONArray of values would perhaps be OK as well... but something that implements the List interface is nice).