The issue here is the incorrect @Builder annotation on the parent class. The documentation for @SuperBuilder mentions:
Most importantly, it requires that all superclasses also have the
@SuperBuilderannotation.
So the correct parent class would be:
@Data
@SuperBuilder // <- annotation replaced here
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class Party {
protected Long id;
protected String status;
}
Addendum:
A key difference between both annotations is that @SuperBuilder also creates a constructor of the class expecting a corresponding builder argument.
For Party it would look like:
protected Party(PartyBuilder<?, ?> b) {
this.id = b.id;
this.status = b.status;
}
and for Person:
protected Person(PersonBuilder<?, ?> b) {
super(b);
this.name = b.name;
this.sex = b.sex;
}
As you can see, the child class constructor wants to pass its own builder to the parent class constructor and this will only be possible if there is a matching constructor there, and @Builder wouldn't generate it.
Also PersonBuilder<> extends PartyBuilder<>, that is why calling super with the child type builder works fine here.