Trying to parse the string JSON response to JAVA POJO using Jackson annotation in Spring boot application.
POJO
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY )
@JsonRootName(value = "data")
public class Data {
@JsonProperty("ticket")
private String ticket;
public String getTicket() {
return ticket;
}
public void setTicket(String ticket) {
this.ticket = ticket;
}
@Override
public String toString() {
return "\"data:\"{" + "\"ticket\"=\"" + ticket + "\"}";
}
}
Retrieving the ticket from third party API using postForEntity as follows
ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
However, the third party API sends JSON in string format.
Want to convert this JSON string to JAVA POJO using Jackson annotations.
So that the call to API would become
ResponseEntity<Data> response = restTemplate.postForEntity(url, entity, Data.class);
Any help would be appreciated.
Thanks!