message.put("method", methodTag);
JSONArray params= new JSONArray();
if (args!=null) {
for(Object arg: args) {
SerializerState state= new SerializerState();
params.put(message2Object.marshall(state, arg));
}
}
message.put("params", params);
message.put("id", 1);
JSONObject responseMessage= session.sendAndReceive(message);
if (!responseMessage.has("result"))
processException(responseMessage);
Object rawResult= responseMessage.get("result");
if (rawResult==null) {
processException(responseMessage);
}
Class<?> returnType= method.getReturnType();
if (returnType.equals(Void.TYPE))
return null;
SerializerState state= new SerializerState();
return message2Object.unmarshall(state, returnType, rawResult);
}