tags:

views:

165

answers:

1

My backend server function returns a list of json object to the caller.

I would like to use JsonRequestBuilder to interact with this backend function

I defined a AsyncCallback this way

class MyCallBack extends AsyncCallback<List<MyObject>> {

However, JsonpRequestBuilder does not this declaration AsyncCallback because the generic type is bounded to <T extends JavaScriptObject>. List<MyObject> does not satisfy this requirement.

Do you have any suggestion to this problem?

+2  A: 

See this example from the docs for JsonpRequestBuilder

class Feed extends JavaScriptObject {
  protected Feed() {}

  public final native JsArray<Entry> getEntries() /*-{
    return this.feed.entry;
  }-*/;
}

Instead of the response being a straight List, the response is a JavaScriptObject that contains a JS array, which is exposed via the JSNI getEntries() method.

If the JSON response doesn't name the array (like var feed = [...]) then I believe you can just do return this but you'd have to try it to be sure. Hope this helped.

Jason Hall