使用默认的ObjectMapper

时间:2018-12-03 12:08:05

标签: java json eclipse boolean objectmapper

我有带有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());

1 个答案:

答案 0 :(得分:2)

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

,将setter-getter设置为

public boolean isBlocked()
    {return blocked;}

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