我有以下代码以String和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);
它适用于特定的URL,更改URL后,出现以下错误(得到空响应):
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)
我的回应VO:
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResponseVO {
@JsonProperty("isBlocked")
private boolean blocked;
private String responseId;
//getters and setters
我需要在responseString
上添加支票吗?仅检查不为空?无效的回应呢?可以/应该在发生错误时创建一个空对象吗?
其他answers与我的情况无关