更改URL时获取JsonMappingException:由于输入结束,没有要映射的内容

时间:2018-12-18 08:30:18

标签: java json objectmapper jackson-databind

我有以下代码以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与我的情况无关

0 个答案:

没有答案