JSON parse error: Cannot construct instance of “xxx“(although at least one Creator exists)
•
数据库
今天写SpringBoot出现一个错误
JSON parse error: Cannot construct instance of `priv.kuki.param.AddressListParam` (although at least one Creator exists)
原因
@Data
@NoArgsConstructor // 加上该注解解决问题
public class AddressListParam {
@NotNull // 加注解报错
@JsonProperty("user_id")
private Integer userId;
}
这是一个通过id查询地址的接口,我给id加上不为空的注解后,出现JSON反序列化错误。
解决方案
在类上加上@NoArgsConstructor注解。
错误原因
- 错误的原因是没有无参构造函数,
- json在转对象反序列化的时候,需要先初始化对象,默认调用无参构造函数,再赋值,
- 因而需要创建无参构造器。
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/b45af880f8.html
