Retrieving JSON data via HTTP GET using Spring Android Framework
I am using spring android framework for retrieving json data via Http GET. I am getting following exception for the same :
- Could not read JSON: Can not deserialize instance of com.springandroidjsondemo.beans.LoginBean[] out of START_OBJECT token
The bean (LoginBean) is Following
Code:
package com.springandroidjsondemo.beans;
public class LoginBean {
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
The android code is following :
Code:
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "json")));
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson message converters
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
// Make the HTTP GET request, marshaling the response from JSON to an array of Events
ResponseEntity<LoginBean[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity,LoginBean[].class); // getting exception here
LoginBean[] loginBean = responseEntity.getBody();
String status = loginBean[0].getStatus();
The json response from the server is following :
Code:
{"emp-data":[{"status":"true"}]}
I am not sure if any annotations are required for Jackson Marshalling
Please suggest the solution
Thanks!