pojobuilder icon indicating copy to clipboard operation
pojobuilder copied to clipboard

.withoutCustomer()

Open nbudzyn opened this issue 9 years ago • 4 comments

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?

nbudzyn avatar Jul 14 '15 13:07 nbudzyn

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...)

mkarneim avatar Aug 14 '15 10:08 mkarneim

I have to think about how this could be realized.

Great!

withUnsetterProperties = true, withUnsetterNamePattern = "without*"?

Which would yield .withoutCustomer().

nbudzyn avatar Apr 08 '16 12:04 nbudzyn

I'd just like to say that I would very much welcome this feature, too :-)

pleibfried avatar Oct 24 '18 14:10 pleibfried

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())

Adrodoc avatar Mar 04 '19 22:03 Adrodoc