I am getting json using rest templete
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
test = restTemplate.getForObject(url,Test.class, params);
I am getting json like
{"object":"{\"id\":123,\"userId\":159,\"contentId\":1}"}
Here is my POJO
@JsonIgnoreProperties(ignoreUnknown = true)
public class Test {
@JsonProperty("id")
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
But I am getting error
[Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@9bd513b; line: 1, column: 75] (through reference chain: nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.soham.Test] from String value ('{"id":123,"userId":116,"contentId":0}'); no single-String constructor/factory method
Update: I have tried to add a constructor
public Test(String id){
this.id=id;
}
It's not showing the error then.But it's printing the whole json
{"id":123,"userId":116,"contentId":0}
How to solve?Any idea?