3

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!

  • Take a look at this post: https://stackoverflow.com/questions/9381665/how-can-we-configure-the-internal-jackson-mapper-when-using-resttemplate. Configure MessageConverters for RestTemplate. It will do the serialization and desrialization work for you. – Rana_S Jun 14 '17 at 14:50

0 Answers0