【发布时间】:2014-05-13 15:06:07
【问题描述】:
目标
我想使用 JSON-RPC 在客户端发送这个:
{"jsonrpc":"2.0","method":"RegisterValues","params":[["Planets","Stars"]],"id":2}
我的尝试
使用 Resty-GWT:
public interface testService extends RestService {
@Produces("application/json")
@POST
public void myCall(Params myparams, MethodCallback<Response> callback );
public class Params {
String jsonrpc = "2.0";
String method;
//String[] params;
Map<String, String> params;
int id;
public void setId(int id){
this.id = id;
}
public void setMethod(String method){
this.method = method;
}
}
public void setParams(Map<String, String> params){
this.params = params;
}
}
当我在另一个类中调用 Params 对象(设置调用)时,执行以下操作:
Map<Integer, String> myParams = new HashMap<Integer, String>();
myParams.put(0, "Planets");
myParams.setParams(myParams);
显然这会像这样发送它:
{"jsonrpc":"2.0", "method":"RegisterValues", "params":{"0":"Planets"}, "id":0}
我不知道如何获得这些魔法:[["Planets"]]
我尝试使用String[],但这给了我结果:["Planets"]
String[][] 给出它尚不支持的错误。
可怕的黑客攻击
如果我在testService 中传递String 为:
String myparams = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FPlanets\"]],\"id\":2}";
它有效,但显然这太可怕了。
我尝试使用 GSON 对 POJO 进行编码,但 GWT 不允许反射。我尝试使用thetransactioncompany 将对象解析为“字符串”,但在gwt.xml 文件中找不到我需要的<inherits>。
有什么想法吗?
【问题讨论】:
标签: java json gwt json-rpc resty-gwt