khaintt / android-json-rpc

Automatically exported from code.google.com/p/android-json-rpc
0 stars 0 forks source link

JSONRPCClient doesn't handle parameter of type array. #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call remote function with signature foo(int[] blah);

What is the expected output?:
Server should receive [1,2,55] as the param.

What do you see instead?:
Server receives "["\id98459875" which is a result of toString() on array.

What version of the product are you using?:
latest

FIX:
    protected JSONObject doRequest(String method, Object[] params)
            throws JSONRPCException, IOException {
        // Copy method arguments in a json array
        JSONArray jsonParams = new JSONArray();
        for (int i = 0; i < params.length; i++) {
            //[by gnugu]: if object is array
            // we need to add JSONArray
            if (params[i].getClass().isArray()) {
                JSONArray param = new JSONArray();
                Object arr = params[i];
                int len = Array.getLength(arr);
                for (int j = 0; j < len; j++) {
                    param.put(Array.get(arr, j));
                }
                jsonParams.put(param);
            } else {
                jsonParams.put(params[i]);
            }
        }

        // Create the json request object
        JSONObject jsonRequest = new JSONObject();
        try {
            // id hard-coded at 1 for now
            jsonRequest.put("id", 1);
            jsonRequest.put("method", method);
            jsonRequest.put("params", jsonParams);
        } catch (JSONException e1) {
            throw new JSONRPCException("Invalid JSON request", e1);
        }
        return doJSONRequest(jsonRequest);
    }

Original issue reported on code.google.com by rho...@gmail.com on 27 Oct 2010 at 10:09

GoogleCodeExporter commented 9 years ago
Thanks for posting this fix.
I will commit it and make a release this week end 

Original comment by alexd6...@gmail.com on 28 Oct 2010 at 11:34

GoogleCodeExporter commented 9 years ago
Hi, Did this get fixed? I am experiencing a similar issue trying to send a 
JSONArray, the server is receiving a string. 

Original comment by fra...@fraserhardy.co.uk on 13 Jan 2012 at 2:17

GoogleCodeExporter commented 9 years ago
You can fix it yourself in your own code for the time being.
The fix is posted above.

Original comment by rho...@gmail.com on 13 Jan 2012 at 8:28

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is has been fixed with version 0.3.1

Original comment by Spd...@gmail.com on 8 May 2012 at 1:05