androidresttemplaterobospicespring-android

Robospice loadDataFromNetwork() not working


I am using spring android in robospice. I need to place headers with get request so i used exchange() method. The code has no error but does not fetch anything

public MList loadDataFromNetwork() throws Exception {
        HttpHeaders headers = new HttpHeaders();
        headers.add(key,keyValue);
        HttpEntity entity = new HttpEntity(headers);
        ResponseEntity<MList> response=getRestTemplate().exchange(url,HttpMethod.GET,entity,MList.class);
        return getRestTemplate().exchange(url, HttpMethod.GET,new HttpEntity<Object> (headers),MList.class).getBody();
    }

Solution

  • RestTemplate restTemplate=new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        HttpHeaders headers = new HttpHeaders();
        headers.add(key,keyValue);
        HttpEntity entity = new HttpEntity(headers);
        ResponseEntity<Pojo> response=restTemplate.exchange(url,HttpMethod.GET,entity,Pojo.class);
        return response.getBody();
    

    It worked when I edited the code like this.

    But I got a null pointer exception when used

     RestTemplate restTemplate=getRestTemplate();
     restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter())