报错信息:Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.j

记录一次spring boot整合layui加security查询List接口返回接口异常报错


实现了UserDetails接口
报错信息:Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.j

Mapper接口
报错信息:Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.j
前台直接注入Mapper然后调用接口
报错信息:Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.j
后台一切运行正常然后到前台报一个500,报错信息如下

{timestamp: “2020-09-21T07:02:23.328+00:00”, status: 500, error: “Internal Server Error”,…}
error: “Internal Server Error”
message: “Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.example.layuidemo.until.ResultUntil[“data”]->java.util.ArrayList[0]->com.example.layuidemo.entity.User[“authorities”])”
path: “/userlist”
status: 500
timestamp: “2020-09-21T07:02:23.328+00:00”
trace: “org.springframework.http.converter.HttpMessageNotW”

前台页面也显示接口异常

后来排查了很久终于发现是User类继承了UserDetail类而发生的错误,
User类中有一个对应的roleList为空,数据传到前台就发生了接口错误,具体原因不知,最后换了一个UserVo类,问题解决。