0

I'm using Apache Wink for implementing REST Services and I can't seem to receive parameters of type array or List. The call is being made from ajax $.post:

$.post(url,
    {   param: ['string1', 'param2', 'x', 'etc...etc....etc'], 
        str2: "str2"},
    function(data) {// do something     
}); 

On the server side, Strings and ints are correctly received, but the 'param' parameter is always received empty (not null, but with zero elements), whether the variable is defined as String[], List, Set, ... . The receiving function is defined as:

@POST @Produces("application/json") @Path("eee") 
public Response eee(@FormParam("str1") String str1, @FormParam("param") String[] param, @FormParam("str2") String str2)

While debugging, I can see a context variable with a table entry like:

wink.formParameters=[param%5B%5D=string1,param%5B%5D=param2,param%5B%5D=x,param%5B%5D=etc...etc....etc,str2=str2]

That translates to 'param[]=string1, param[]=param2, ..', no indexation. Don't know if that's correct.

Any ideas ?

user1292542
  • 1
  • 1
  • 1

2 Answers2

2

I realize this is an old question, but I had a similar problem, and I ended up fixing it by adding [] to the end of the FormParam name.

So instead of having @FormParam("param"), you would have @FormParam("param[]")

Note that I am also using jQuery's $.params method to serialize my data, but I it looks like your debugging revealed a properly-encoded form string, so I'm suspecting it's just the [] that are missing.

-1

This works for me when I define the accepting variable as :

@FormParam("paramName") List<String> paramList;

You might also need to tweak the client call like:

$.post(url,
    {   paramName: "string1", 
    {   paramName: "string2",
    {   paramName: "string3",
        str2: "str2"},
    function(data) {// do something     
});
  • Some syntax issues there. But with data {x: "string1", x:"string2", x:"string3", str: "str"} and List declaration, the list only gets 1 element (the last one). – user1292542 Mar 30 '12 at 09:35