我有带boolean(isBlocked)参数的JSON响应

{"isBlocked":true,"responseId":"ab123456789", "other":"irrelevant"}


我的ResponseVO(使用Eclipse自动生成的getter和setter):

@JsonIgnoreProperties(ignoreUnknown = true)
public class ResponseVO {

private boolean isBlocked;
private String responseId;
public boolean isBlocked() {
    return isBlocked;
}
public void setBlocked(boolean isBlocked) {
    this.isBlocked = isBlocked;
}
public String getResponseId() {
    return responseId;
}
public void setResponseId(String responseId) {
    this.responseId = responseId;
}


}

我正在使用ObjectMapper设置VO对象

ResponseVO responseVO = new ObjectMapper().readValue(response, ResponseVO.class);


但是布尔参数设置为false而不是true

logger.debug("SpelPaus Block=" + responseVO.isBlocked());

最佳答案

将private属性重命名为private boolean blocked;

和setter-getter为

public boolean isBlocked()
    {return blocked;}

public void setBlocked(boolean blocked)
    {this.blocked = blocked;}

08-16 16:47