org.springframework.http.converter.HttpMessageNotReadableException异常解决

问题现场还原

最近研发过程中,后台代码是这么写的:

    @ApiImplicitParam(name = "X-Token", value = "登陆用户Token",required = true, dataType = "String",paramType="header")
    @PostMapping(value = "/update-advert-status.do")
    public VueElementAdminResponse updateAdvertStatus(@RequestBody AdvertUpdateParam advertUpdateParam){
          ...
  }

实体类是这么写的:

import lombok.Data;
/**
 * @author qing-feng.zhao
 */
@Data
public class AdvertUpdateParam{
    private String id;
    private Integer status;
}

后台出现了这个错误:

2020-08-14 06:55:10.141 WARN  --- o.s.w.s.m.s.DefaultHandlerExceptionResolver --- org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:199:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected end-of-input: expected close marker for Object (start marker at [Source: (PushbackInputStream); line: 1, column: 1]); nested exception is com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: (PushbackInputStream); line: 1, column: 1])
 at [Source: (PushbackInputStream); line: 3, column: 14]]

解决方案

一种原因是页面传参和后台不符异常org.springframework.http.converter.HttpMessageNotReadableException。

另外一种是被@RequestBody 修饰的请求参数实体类没有实现序列化接口,如果不序列化就会出错。

修复代码如下所示:

import lombok.Data;

import java.io.Serializable;

/**
 * @author qing-feng.zhao
 */
@Data
public class AdvertUpdateParam implements Serializable {
    private static final long serialVersionUID = -1242493306307174690L;
    private String id;
    private Integer status;
}

本篇完~

你可能感兴趣的:(星云的踩坑笔记本)