There are various ways someone might want to customize builders and I dont think it is lombok's purpose to define them all.
The
mechanism I read somewhere and now use for default properties is to
define my own builder method. I change the name of the lombok generated
builder to something like "unsafeBuilder" using the @Builder annotation
parameters, and define my own static builder() method which call the
unsafe one and sets the default values before returning the builder
object.
@Builder(builderMethodName = "unsafeBuilder")
public class Blah {
...
public static BlahBuilder builder() {
return unsafeBuilder().prop1("
safeDefaultValue").prop2("safeDefaultValue");
}
I've
found this to be clean and very workable. I would use the same pattern
for a copy builder, which I would name seomthing like buildFrom(Object
source), and copy the original values to the unsafe builder before
returning it.
@Builder(builderMethodName = "unsafeBuilder")
public class Blah {
...
public static BlahBuilder buildFrom(Blah source) {
return unsafeBuilder().prop1(source.getProp1()).prop2(source.getProp2);
}