user222 user222 - 10 months ago 49
reST (reStructuredText) Question

error while calling a rest webservice

I have a rest webservice which returns

. Please see the code below.

@RequestMapping(value = MyRequestMapping.GET_SIG_DATA, method = RequestMethod.GET)
public List<String> getSigDataValues(@PathVariable final String acc, final HttpServletResponse response)
throws Exception {

List<String> dataList = null;
try {
//logic goes here
} catch (Exception e) {
LOG.error("Exception" + e);
return dataList;

The above webservice is not returning any responseDTO object, it just returns a list of String type.

I want to call above webservice from another application.Below is my code.

public List<String> getSigData(String acc){

return restTemplate.postForObject(DataURL.GET_SIG_DATA.value(), MyRequestDTO.class,MyResponseDTO.class, acc);

When compiling its throwing the below error message:

[javac] found :
[javac] required: java.util.List<String>
[javac] return restTemplate.postForObject(DataURL.GET_SIG_DATA.value(), MyRequestDTO.class,MyResponseDTO.class,acc);

Please suggest where i am going wrong.

Answer Source

Try this

 public List<String> getSigData(String acc){

       return (List<String>)restTemplate.postForObject(DataURL.GET_SIG_DATA.value(), List.class,List.class, acc);