Elgallati Noreddine
Elgallati Noreddine

Reputation: 139

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

Upvotes: 0

Views: 8359

Answers (3)

Ahmed Salem
Ahmed Salem

Reputation: 1757

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.

Check below images for more details

Sample API , POST , Take only one parameter

Example how to pass parameter from postman

Upvotes: 0

Issam El-atif
Issam El-atif

Reputation: 2486

Your getter and setter methods for isActive should be getIsActive and setIsActive without underscore

public Integer getIsActive() {
        return isActive;
}

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

Upvotes: 0

mhasan
mhasan

Reputation: 3709

I believe your JSON for isActive is of boolean isActive : true It is expecting to be of type boolean not integer. This is makes your Jackson

Change your private Integer isActive; to private boolean isActive;

Upvotes: 3

Related Questions