I'm trying to use Spring Retry for Jackson deserialization into a POJO object like so:
@Data
public class myPOJO {
private String cmpStr = "test";
private String myStr;
@Retryable(maxAttempts=3, value=RuntimeException.class, backoff=@Backoff(delay=3000))
@JsonProperty("jsonElement")
private void retryableFunc(Map<String, Object> jsonElement) {
try {
myStr = jsonElement.get("jsonAttribute");
if (!Objects.equals(myStr, cmpStr))
throw new RuntimeException("Bad Response");
}
catch (Exception e) {
throw new RuntimeException("Bad Response");
}
}
@Recover
private void recover(Exception e) {
System.out.println("Recover triggered");
}
}
MyPOJO is instantiated like this:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singleTonList(MediaType.APPLICATION_JSON));
String jsonAttribute = restTemplate.exchange(URL, HttpMethod.GET, new HttpEntity<>(headers), myPOJO.class).getBody().getMyStr();
Main app looks like:
@SpringBootApplication
@EnableRetry
public class mainApplication {
public static void main(String[] args) {
SpringApplication.run(mainApplication.class, args);
}
}
JSON response looks like this:
{
"jsonElement": {
"jsonAttribute": "test1"
}
}
Retry is never triggered, but the exception is thrown:
Error while extracting response for type myPOJO and content type [application/json;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Bad Response; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Bad Response