目的
我想使用JSON-RPC發送此對客戶方:編碼Java對象(POJO)轉換成JSON字符串在GWT
{"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[][]
給出了它尚未支持的錯誤。
可怕的哈克
如果我通過在String
我testService
爲:
String myparams = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FPlanets\"]],\"id\":2}";
它的工作原理,但顯然這是可怕的。
我嘗試使用GSON編碼POJO,但GWT不允許反射。我嘗試使用thetransactioncompany來解析對象爲'String',但無法弄清我需要在我的gwt.xml
文件中的<inherits>
。
有什麼想法?
感謝您的詳細和精心佈置的答案 – fiz