cannot deserialize from Object value?

最近在spting boot中写后端的接口,遇到了一个反序列化出错的的问题,报错代码如下:

在后端接口接收具体类的对象时,需要在对象的定义里面添加上无惨构造函数。

cannot deserialize from Object value?

{"success": false,
    "message": "Type definition error: [simple type, class cn.com.bii.statistics.entity.UpdateAll]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `cn.com.bii.statistics.entity.UpdateAll` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: (PushbackInputStream); line: 2, column: 5]",
    "code": 500,
    "result": null,
    "timestamp": 1631066550907
}

分析:原因是在构造类的时候没有写无参构造函数,当然通常情况下是会默认有无参构造函数的,这是我写了一个有参构造函数之后没有把无参构造函数补上导致的。

所以记下来提醒自己在写完有参构造函数时记得同时加上无参构造函数。

public class UpdateAll {
@ApiModelProperty("修改之前的信息")
private Object before;

@ApiModelProperty("修改之后的信息")
private Object now;

@ApiModelProperty("其余信息")
private Object others;

public UpdateAll(){} //添加无参数构造函数

posted @ 2021-09-08 10:14  The-Chosen-One  阅读(798)  评论(0编辑  收藏  举报