I have the following code to get response as String and Object
try (CloseableHttpClient httpClient = getHttpClient();
CloseableHttpResponse response = httpClient.execute(target, post)) {
String responseString = EntityUtils.toString(response.getEntity());
ResponseVO responseVO = new ObjectMapper().readValue(responseString, ResponseVO.class);
It's working for specific URL, after changed the URL, I'm getting the following error (getting empty response):
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: ; line: 1, column: 0]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:255)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3851)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3792)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2797)
My ResponseVO:
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResponseVO {
@JsonProperty("isBlocked")
private boolean blocked;
private String responseId;
//getters and setters
Do I need to add checks on responseString
? check only not empty? what about invalid response? can/should I create an empty object in case of an error?
Other answers are not relevant to my case