【发布时间】:2014-05-12 10:45:46
【问题描述】:
问题
由于对 GSON 的各种烦恼,目前我正在用 Resty-GWT 替换 GSON 来进行 JSON-RPC 调用。它完全按照我想要的方式工作,但除了String 之外,我不知道如何发送消息:
String names_ = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FirstValue\"],\"id\":2}";
我想以更智能的方式执行此操作,因此我不必写出所有这些值。最重要的是,我想要一种简单的方法来插入这些参数。在我的请求负载中轻松声明这些属性的某种方式。
当前方法
这个String是通过这个调用发送的:
testService.RegisterValues(names_, new MethodCallback<testService.Response>(){
@Override
public void onFailure(Method method, Throwable exception) {
// TODO Auto-generated method stub
Window.alert(exception.getMessage().toString());
}
@Override
public void onSuccess(Method method, testService.Response response) {
// TODO Auto-generated method stub
Window.alert("Hello" + response.getResult().toString());
}
});
testService 类位于此处:
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.RestService;
public interface testService extends RestService {
@Produces("application/json")
@POST
public void RegisterValues(String names_, MethodCallback<Response> callback );
}
然后回调被发送到这个响应类,在那里我可以轻松地反序列化数据,提取(虽然这在这里并不重要):
public class Response {
private int id;
private Map<String, Map<String, Integer>> result;
private String error;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
//...etc.
【问题讨论】:
标签: java gwt json-rpc resty-gwt