Hi All,
I am trying to parse indexed request parameter sent in post request.
This is the html which I am using to make the request:
<form action="rest/resource method="POST">
<label >Address 1</label><input name="*address*[]" />
<br/>
<label >Address 2</label><input name="*address*[]" />
<br/>
<label >Address 3</label><input name="*address*[]" />
<br/>
<input type="submit" value="Submit" />
</form>
at the server side here are different combination that I tried (none of
this works):
1.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Address setAddress(*_at_FormParam("address") String[] address* ) {
....
}
2.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Address setAddress(*_at_FormParam("address[]") **String[]**
address* ) {
....
}
3.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Address setAddress(*_at_FormParam("**address**") List<String>
address* ) {
....
}
4.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Address setAddress(*_at_FormParam("**address[]**") List<String>
address* ) {
....
}
From FormParam's documentation:
"The type |T| of the annotated parameter must either:
1. Be a primitive type
2. Have a constructor that accepts a single |String| argument
3. Have a static method named |valueOf| that accepts a single
|String| argument (see, for example, |Integer.valueOf(String)|)
4. Be |List<T>|, |Set<T>| or |SortedSet<T>|, where |T| satisfies 2 or
3 above. The resulting collection is read-only."
Using List<String> satisfies the condition 4 mentioned above but it
doesn't work.
Can anybody suggest how to retrieve the indexed parameter without using
MultivaluedMap?
Thanks
-Rahul