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)
网上搜索得知是反序列化失败了,看到这俩解决办法
- 需要转换的entity没有getter/setter(本次受此影响,这个不能漏,如果懒得写可以考虑lombok)
- 没有实现Serializable(本次并不直接对其序列化传输,不涉及)
代码如下
@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);
}
}
标签:definition,xxx,CommonResult,Object,private,序列化,class
From: https://www.cnblogs.com/Morning-Glory/p/18058584