我将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;
}
可能是什么原因?
答案 0 :(得分:2)
尝试向您的班级添加@AllArgsConstructor
和@NoArgsConstructor
批注
答案 1 :(得分:1)
这是lombok版本1.16.20中的一个已知问题。 https://github.com/rzwitserloot/lombok/issues/1563
您可以这样做:
@Getter
@Builder
@JsonDeserialize(builder = AccountItem.AccountItemBuilder.class)
public class AccountItem {
/**
* Accounti dentifier
*/
private Long accountId;
/**
* Account name
*/
private String accountName;
/**
* Account priority
*/
private int accountPriority;
@JsonPOJOBuilder(withPrefix = "")
public static final class AccountItemBuilder {
}
}