简体   繁体   English

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

[英]JsonMappingException can not deserialize instance of java.lang.Integer

I am trying to insert object in my database but i am getting this error 我正在尝试在数据库中插入对象,但出现此错误

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"])

my code is: 我的代码是:

@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;
    }

I believe your JSON for isActive is of boolean isActive : true It is expecting to be of type boolean not integer. 我相信您的isActive的JSON为boolean isActive : true期望为boolean类型而不是整数。 This is makes your Jackson 这是让你的杰克逊

Change your private Integer isActive; 更改您的private Integer isActive; to private boolean isActive; private boolean isActive;

Your getter and setter methods for isActive should be getIsActive and setIsActive without underscore 您对isActive的getter和setter方法应为getIsActive和setIsActive,且不带下划线

public Integer getIsActive() {
        return isActive;
}

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

If you are trying to test the API throw postman you , And if you have only on input of type integer you should send it direct to body without json object braces. 如果您想测试API投掷邮递员,并且,如果您只有整数类型的输入,则应将其直接发送到正文,而无需使用json对象括号。

Check below images for more details 查看下面的图片以获取更多详细信息

示例API,POST,仅接受一个参数

示例如何从邮递员传递参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JsonMappingException:无法从START_OBJECT标记中反序列化java.lang.Integer的实例 - JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token 无法在查询中反序列化`java.lang.Integer` 的实例 - Cannot deserialize instance of `java.lang.Integer` in a Query JsonMappingException:已为(java.lang.Integer)使用POJO - JsonMappingException: Already had POJO for (java.lang.Integer) MismatchedInputException:无法从 START_OBJECT 令牌反序列化 `java.lang.Integer` 的实例 - MismatchedInputException: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token JsonMappingException:无法从START_OBJECT令牌1中反序列化java.lang.String实例 - JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token 1 如何修复此错误“JSON 解析错误:无法从 START_OBJECT 中反序列化 `java.lang.Integer` 的实例 - How to Fix This ERROR "JSON parse error: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT 无法在Hibernate中将java.lang.Integer字段…User.id设置为java.lang.Integer异常 - Can not set java.lang.Integer field …User.id to java.lang.Integer exception in Hibernate 无法将 java.lang.Integer 字段设置为 java.lang.ZA0FAEF0851B4194C46F2B2B - Can not set java.lang.Integer field to java.lang.Integer Jackson JsonMappingException:无法反序列化实例 - Jackson JsonMappingException: Can not deserialize instance org.codehaus.jackson.map.JsonMappingException:无法从START_ARRAY令牌中反序列化java.lang.Long的实例 - org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.Long out of START_ARRAY token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM