2016-10-04 1193 views
0

我想在我的數據庫中插入對象的實例,但我得到這個錯誤JsonMappingException無法反序列化java.lang.Integer中

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: [email protected]; 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: [email protected]; 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; 
    } 
+0

Integar是標量,試圖讓「字符串」 json的值。檢查這個線程https://github.com/FasterXML/jackson-dataformat-xml/issues/139 –

回答

0

我相信你isActive的JSON是布爾值isActive : true 它期望的布爾類型不是整數。 這是使你的傑克遜

更改isActive您private Integer isActive;private boolean isActive;

+0

謝謝,它解決了這個問題 –

0

你的getter和setter方法應該是getIsActive和setIsActive,沒有下劃線

public Integer getIsActive() { 
     return isActive; 
} 

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