RestService and RestTemplate

My Spiring  RestService delete method has signature :

public ResponseEntity<?> delete(@RequestBody List<Long> IdList)

Question :
I am making a client code and trying to send  list of  long id's to  my above service  with the help of  RestTemplate  delete .  But it seems RestTemplate delete method does not accept list of long ids . How to fix this ?

Here is the client code:

RestTemplate.delete("/bsi/extgd/v1" + [2,3,4]);  //  this does not work... as I cant send list of long ids here

Is there any way to send   list of long ids to delete method  ?
Who is Participating?
cofactorAuthor Commented:
got some workaround to this . ,,may be useful to others .

solution is :

HttpEntity <Long> httpEntity = new HttpEntity <Long> (Id , header);
Object, HttpMethod.DELETE, httpEntity,new ParameterizedTypeReference<String>() {});
cofactorAuthor Commented:
any comments ?
mccarlIT Business Systems Analyst / Software DeveloperCommented:
But it seems RestTemplate delete method does not accept list of long ids

This is because the HTTP DELETE method is generally not used with a request body at all, and so RestTemplate has no methods for passing any body content.

So the options are to just hack together a solution. It's probably easier but is less "RESTful" (that may or may not be important to you). Or if you are trying to adhere to the REST ideals, I would go with the idea of creating a new resource (i.e. with a POST call), and the resource is actually a list (or selection) of other resources. The server creates this list and then returns a generated id for this new list resource. Then you can DELETE this resource and it will delete the resources specified in the list. The source of the idea and other useful info is here.
cofactorAuthor Commented:
there was issue in adding correct data type which I rectified.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.