Spring RestTemplate passing the type of the response

1k Views Asked by At

I am using Spring RestTemplate to make a GET call with a request body.

So I am making a bunch of web service calls using the rest template. For each one of them they support getting a resource passing a query as a request body parameter. I am using the following to pass the body :

 Map<String, String> requestBody = new HashMap<String, String>();
 requestBody.put("type", "Sandwich");
 requestBody.put("flavor", "blueberry");
 MultiValueMap<String, Map<String, String>> body = constructQueries(requestBody); //see below
 HttpEntity request = new HttpEntity(body, headers);
 ResponseEntity<T> response = restTemplate.exchange("http://myurl.com/ids", HttpMethod.GET, request, type);

I am constructing the body as follows:

private MultiValueMap<String, Map<String, String>> constructQueries(Map<String, String> pBody){
    MultiValueMap<String, Map<String, String>> body = new LinkedMultiValueMap<String, Map<String, String>>();
    //List<Map<String, String>> queryLists = new ArrayList<Map<String, String>>();
    for (Map.Entry<String, String> entry : pBody.entrySet())
    {
        Map<String, String> singleQuery = new HashMap<String, String>();
        singleQuery.put("field", entry.getKey());
        singleQuery.put("value", entry.getValue());
        body.add("query", singleQuery);                 
    }

    return body;
}

My body (in JSON) is supposed to look like this:

{ "query": [ { "field" : "type", "value": "Sandwich" } , { "field" : "flavor", "value": "blueberry" }] }      

But when I look at the server side received request, the body is not passed at all. Does rest template not support passing body for GET calls?

0

There are 0 best solutions below