org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: (was java.lang.NullPointerException) (through reference chain: com.smart.dao.Page["content"]->java.util.Collections$UnmodifiableRandomAccessList[3]->com.smart.model.coupon.Coupon["title"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.smart.dao.Page["content"]->java.util.Collections$UnmodifiableRandomAccessList[3]->com.smart.model.coupon.Coupon["title"])
在实体中有:
public String getTitle() {
if(CouponType.DEDUCT_FEE.equals(type)) {return name + "面值" + faceValue.longValue() + "元";
}
else {
return name + "面值" + faceValue.floatValue() + "%";
}
}
而在数据库中存在:type=null 的数据
把数据删掉吧.
解决HttpMessageNotWritableException异常
本文探讨了在Spring框架中遇到的org.springframework.http.converter.HttpMessageNotWritableException异常,特别是当尝试序列化含有空指针的对象时触发的问题。通过分析异常堆栈跟踪,发现是由于数据库中存在type为null的Coupon实例导致的。最终解决方案建议删除这些不一致的数据记录。
4664

被折叠的 条评论
为什么被折叠?



