Hello,
I need to send an ordered lit of objects to a GWT client.
Here is the solution I found, it works, but I am prety sure that tere is a more
efficient solution :
My code on the server side :
public class TestArrayOfjObjectRessource extends ServerResource {
@Get("json")
public Representation toJson() throws ResourceException {
List<Object> list = new ArrayList<Object>();
MyClass myObject_1 = new MyClass;
MyClass myObject_2 = new MyClass;
list.add( new JsonRepresentation(myObject_1).getJsonObject());
list.add( new JsonRepresentation(myObject_2).getJsonObject());
JsonRepresentation jr = new JsonRepresentation(new
JSONArray(list));
return jr;
}
}
On client side :
jsonButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ClientResource r = new
ClientResource("/restlet/simpleTestRessource");
r.setOnResponse(new Uniform() {
public void handle(Request request, Response
response) {
Representation myEntity = response.getEntity();
JsonRepresentation jRep = new
JsonRepresentation(myEntity);
try {
JSONObject jsonObject =
jRep.getValue().isObject();
respAreaLabel.setText(jsonObject.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
});
// Indicates the client preferences and let the server handle
// the best representation with content negotiation.
r.get(MediaType.APPLICATION_JSON);
}
});
==> the displayed result is [{...},{...}] what is the expected result.
does anyone have an idea if my solution can be improved.
thanks !
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2645216