I consume a web service that return one of its fields as a String
, but this field is a actually a object, such as below:
{
"message": "OK",
"code": 1,
"supplierPayload": "{\"field01\":\"value01\",\"field02\":\"field02\"}"
}
Is it possible anyway to parse the supplierPayload json field returned as a String
into the SupplierPayload
object I need in the RestTemplate call?
I would have:
this.restTemplate.getForEntity(url, MyObject.class);
And MyObject would be
public class MyObject {
private String message;
private int code;
private SupplierPayload supplierPayload;
// gets and sets
}
instead of
public class MyObject {
private String message;
private int code;
private String supplierPayload;
// gets and sets
}
This will prevent me to have an instance of ObjectMapper Spring bean anywhere I need to use this field and convert it manually handling the nest checked exceptions that ObjectMapper brings in its methods.