Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why @Data and @Builder doesnt work together

I have this simple class

public class ErrorDetails {
    private String param = null;
    private String moreInfo = null;
    private String reason = null;
     ...
}

After refactoring, I added @Data and @Builder, but all the instantiations doesn't work any more

ErrorDetails errorDetails = new ErrorDetails();

'ErrorDetails(java.lang.String, java.lang.String, java.lang.String)' is not public in 'com.nordea.openbanking.payments.common.ndf.client.model.error.ErrorDetails'. Cannot be accessed from outside package

If I removed @Builder, then it will work fine, Why I cannot use @Data and @Builder together?

like image 257
Melad Basilius Avatar asked Feb 21 '26 04:02

Melad Basilius


1 Answers

Lombok's @Builder must have @AllArgsConstructor in order to work

Adding also @AllArgsConstructor should do

Under the hood it build all fields using constructor with all fields

applying @Builder to a class is as if you added @AllArgsConstructor(access = AccessLevel.PACKAGE) to the class and applied the @Builder annotation to this all-args-constructor. This only works if you haven't written any explicit constructors yourself.

like image 62
user7294900 Avatar answered Feb 22 '26 17:02

user7294900