controller将返回参数json化后,返回给前端的时候,报异常org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.baomidou.mybatisplus.extension.api.R["data"]->java.util.ArrayList[3]->com.sunflower.sunfloweresreport.modules.system.entity.SysMenuEntity["leaf"])
还要继续看日志:
Caused by: java.lang.NullPointerException: null
at com.sunflower.sunfloweresreport.modules.system.entity.SysMenuEntity.getLeaf(SysMenuEntity.java:100) ~[classes/:na]
原因已经很明确了,该SysMenuEntity类leaf属性是null,导致json化得时候,fasterxml -jackson 将对象转换为json时报错了。
解决方案:
1.首先查看数据是否后问题,因为表结构不一致,数据是否保存完整
2.添加注释@JsonIgnoreProperties,空的时候不序列化
如:
@JsonIgnoreProperties
public class SysMenuEntity extends AdminSuperEntity implements Serializable{
}