JsonMappingException无法反序列化java.lang.Integer的实例

时间:2016-10-04 08:50:24

标签: java spring

我正在尝试在我的数据库中插入对象,但我收到此错误

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.lang.Integer out of VALUE_TRUE token
 at [Source: java.io.PushbackInputStream@745b0b15; line: 1, column: 353] (through reference chain: com.example.beans.Domain["isActive"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Integer out of VALUE_TRUE token
 at [Source: java.io.PushbackInputStream@745b0b15; line: 1, column: 353] (through reference chain: com.example.beans.Domain["isActive"])

我的代码是:

@Entity
public class Domain implements Serializable{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    ...
    private Integer isActive;

    public Integer getIs_active() {
        return isActive;
    }
    public void setIs_active(Integer is_active) {
        this.isActive = is_active;
    }

3 个答案:

答案 0 :(得分:2)

我相信你的isActive JSON是布尔isActive : true 它期望是boolean类型而不是整数。 这是让你的杰克逊

将您的private Integer isActive;更改为private boolean isActive;

答案 1 :(得分:0)

isActive的getter和setter方法应该是getIsActive和setIsActive而不是下划线

public Integer getIsActive() {
        return isActive;
}

public void setIsActive(Integer is_active) {
        this.isActive = is_active;
}

答案 2 :(得分:0)

如果您要测试API投掷邮递员,并且只有整数类型的输入,则应将其直接发送到正文,而无需使用json对象括号。

查看下面的图片以获取更多详细信息

Sample API , POST , Take only one parameter

Example how to pass parameter from postman