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;
}

本篇完~

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值