最近在使用 springBoot 开发的时候, 使用 PostMan 访问接口, 返回一个 404 , 后台报一个 warn :
- Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing:
- public com.syh.foundation.ResponseMessage com.xxxxx.list(xxxxx.vo.AppCostVo)
检查了各个类, 排查了各个可能的地方都没有发现错误, 左后在网上 查找到有人 报 : Failed to write HTTP message 错误, 其解释为:
{
这个异常是我在使用 Spring 中, 在 JavaBean 中使用了包装类 Integer,
private Integer pageNum; 而在方法中使用了 @ResponseBody 注解,
在 return map 返回给前台时 Spring 中的类 com.fasterxml.jackson.databind.JsonMappingException
这个类会对包装类自动拆箱成对应的基本类型, 如果返回的 Integer 中存在 null 的话, 那么在拆箱成 int 时就会报错
如果将 null 赋值给包装类 Integer, 然后将 Integer 赋给各自的基本类型, 编译器不会报, 但是你将会在运行时期遇到空指针异常
这是 Java 中的自动拆箱导致的, 任何含有 null 值的包装类在 Java 拆箱生成基本数据类型时候都会抛出一个空指针异常
}
来源: http://www.bubuko.com/infodetail-2544966.html