后端控制台输出:
WARN 32728 --- [nio-9091-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]
或者
WARN 29304 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
自定义了返回结果封装类Result,其中包含了私有的字段,但没有提供这些字段的getter和setter方法,导致Jackson无法正确序列化出现此错误。
Spring无法序列化私有字段,如果Result类没有getter方法,那么Json的序列化会失败(导致前端406状态码)
解决办法:
提供相应字段的getter和setter方法,如果使用了lombok直接加上@Data注解即可。
另外:Jackson反序列化也需要提供无参构造器