Java 11, Spring Boot and Lombok here. I am trying to build up a hierarchy of objects extending Spring's ApplicationEvent class which forces me to provide a constructor:
public ApplicationEvent(Object source) {
...
}
So extending ApplicationEvent I have a TrackedEvent that is an abstract base class for my other events to build off:
public abstract class TrackedEvent extends ApplicationEvent {
private String correlationId;
private String description;
// ... lots of fields here
}
One of the (many) events extending TrackedEvent is OperationalEvent:
public class OperationalEvent extends TrackedEvent {
private OperationType type;
private OperationStatus status;
// ... several more fields here
}
Other than the source : Object field, which is required by the grandparent ApplicationEvent constructor, all other TrackedEvent and OperationalEvent fields are optional. So because there are so many fields here to populate and instantiation-time, I feel the Builder Pattern is appropriate. So I'd like to employ Lombok's @Builder annotation (and possibly other annos) to obtain an API something like so:
OperationalEvent opsEvent = OperationalEvent.Builder(this)
.description("something happened")
.status(OperationalStatus.THE_THING)
.build();
My thinking here is we would pass this in as a required builder constructor argument (to satisfy ApplicationEvent's constructor for source : Object...somehow) and then use the @Builder like normal.
Is this possible to do in Lombok, and if so, how?
As a fallback I can just write my own builders but since I have so many subclasses it would be great to leverage Lombok if at all possible.