Type definition error: [simple type, class com.elm.po.CommonResult]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
com.elm.po.CommonResult
(no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
网上搜索得知是反序列化失败了,看到这俩解决办法
代码如下
@Data
@AllArgsConstructor
public class CommonResult implements Serializable {
private Integer code;
private String message;
private Object result;
public static CommonResult success (Object object) {
return new CommonResult(200, "success", object);
}
}
可知,实现了Serializable,并且也用了lombok的@Data注解,以上两种方法不能解决问题
问题所在:没有无参构造方法
解决方法:加上@NoArgsConstructor
解决代码:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult implements Serializable {
private Integer code;
private String message;
private Object result;
public static CommonResult success (Object object) {
return new CommonResult(200, "success", object);
}
}