| Issue 20: | Unable to decode array parameter from JSON request on jsonwebservice-ri-0.7.jar | |
| 1 person starred this issue and may be notified of changes. | Back to list |
I recently downloaded and started using jsonwebservice and got the
hello world war up and running. Everything works fine until I try to
submit an array as an argument in the json request. I am using browser URL as
the client side. My request URL is of the format:
http://127.0.0.1:8080/helloWorld/json/hello?methodname.myargs.myarray=[1,2,3]
My webservice method is set up as:
@WebMethod(operationName = "methodname")
public @WebResult(name = "result") String methodname(
@WebParam(name = "myargs") MyParameter myargs)
{ System.out.println(myargs.getMyarray());}
All array parameter moved to one class like bellow
class MyParameter{
ptivate Long[] myarray;
///Getter and setters
}
On the server side, I am getting null from myargs.getMyarray() as console printed.
Jul 2, 2012
Valid way to pass http array parameter is passing one by. In this case valid array passing as follows
http://127.0.0.1:8080/helloWorld/json/hello?methodname.myargs.myarray=1&methodname.myargs.myarray=2&methodname.myargs.myarray=3
In json view it looks strange, but this is NOT json, your trying to pass http parameter.
Here is another way to pass as json
http://127.0.0.1:8080/helloWorld/json/hello?JOSN={methodname:{myargs:{myarray:[1,2,3]}}}
Passing as http parameter most inded to form posting, form posting with array example as follows.
e.g
<form>
<input type="checkbox" name="methodname.myargs.myarray" value="1"/>
<input type="checkbox" name="methodname.myargs.myarray" value="2"/>
</form>
Status:
Invalid
|
Try changing 'MyParameter' class to: class MyParameter{ private ArrayList<Long> myarray; //Getter and setters } Had the same problem and this seemed to fix it. Didn't investigate further; sorry.