pojobuilder
pojobuilder copied to clipboard
.withoutCustomer()
I'm using PojoBuilder withBuilderProperties
, which is great to stick stuff together.
However, I'm experiencing some pain when setting properties to null. As .withCustomer(null)
would be ambiguous, I have to write something like .withCustomer((Customer) null)
.
Wouldn't it be nice if we had no-args methods like .withoutCustomer()
, setting the customer property to null?
Err, I see what you mean...
I have to think about how this could be realized. For example, I guess we have to provide not only a flag which defines if these 'without' methods should be generated, but also the concrete name of these methods (since you also can define the name of the 'with' methods...)
I have to think about how this could be realized.
Great!
withUnsetterProperties = true, withUnsetterNamePattern = "without*"
?
Which would yield .withoutCustomer()
.
I'd just like to say that I would very much welcome this feature, too :-)
There is a really nice workaround for this if you are using @GeneratePojoBuilder(withBuilderProperties=Builder.class)
. Add a method called $null()
:
public static <T> Builder<T> $null() {
return () -> null;
}
And use that method instead of a null
value:
.withCustomer($null())