【发布时间】:2018-07-31 07:45:41
【问题描述】:
我将 Jackson 用作 Json 解析器,但出现错误:
No suitable constructor found for type ~ can not instantiate from JSON object
所以我尝试添加@NoArgsConstructor,但现在我得到了这个:
constructor AccountItem in class AccountItem cannot be applied to given types
这是我的课:
@Getter
@Builder
public class AccountItem {
/**
* Accounti dentifier
*/
private Long accountId;
/**
* Account name
*/
private String accountName;
/**
* Account priority
*/
private int accountPriority;
}
可能是什么原因?
【问题讨论】:
-
你可以试试
@NoArgsConstructor没有@Builder吗? -
它可以在没有
@Builder的情况下工作,但事实是我真的需要这个。 -
您使用的是哪个版本的 lombok?
-
如果你省略
@NoArgsConstructor并自己添加默认构造函数,它是否有效? -
如果使用构建器。您需要添加@AllArgsConstructor。所以你需要两者。 '@AllArgsConstructor' '@NoArgsConstructor'