I'm writing a apache wink controller which contains the following API:
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/users")
public void deleteUsers(List<String> ids) {
// Delete users here.
...
}
I was able to pass the parameter by using @QueryParam("ids") annotation, but this may exceed the URL length limitation when the array is too long. Thus, I want to pass a json object to the controller and I'm wondering 1) what kind of format should the json object be and 2) how can I receive the json object in the server side ?
PS I'm using Jackson in the wink side as the json parser.
Thanks in advance!
I've already tried to pass the following json to wink, but it doesn't seem to work:
{
ids: ['id1', 'id2', ...]
}
First is to create an ObjectMapper instance and then readValue() method with the value type specified in the argument. You'll get the mapped object.
For example:
mapper = new ObjectMapper();
idObject = mapper.readValue(jsonpayload.getBytes(), mapClass);
Also a valid JSON would look like this:
{
"ids" : ["id1", "id2"]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.