不能在课程上使用lombok @NoArgsConstructor

时间:2018-07-31 07:45:41

标签: java jackson lombok

我将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;
}

可能是什么原因?

2 个答案:

答案 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 {
    }
}