@Builder needs a pre-build method/override constructor #71

redijedi opened this Issue Mar 13, 2012 · 3 comments


None yet

3 participants


I have to alter the data a bit on my object before completing the build. I cannot find a way to do so using the Builder annotation. For example, I have an email address field. I want to be able to verify the format of the address and hash the string before building the object. However, I cannot force this behavior. Previously I did so in my class's constructor which accepted a builder of my own creation. I know I can add a method using the callMethods annotation attribute and call it after construction, but this does not enforce the state of the object during instantiation which is preferable when constructing immutable instances.

Ideally I'd like to be able to provide my own constructor so I can enforce invariants. Alternatively the builder's build method could be altered to call one or more methods that I can define and provide by name.


Should be nice also to have a way to specify extra attributes in the builder to be used to call the constructor for the superclass.

@peichhorn peichhorn was assigned Apr 22, 2012

@ggtools I've put your request in a separate issue (#78)

@redijedi I still need to think about a decent way to enable the feature you described.


Done. Simply specify a one argument constructor with Builder as the argumentType, like this:

import lombok.Builder;

class Person {
  private final String name;
  private final String surname;

  private Person(final Builder builder) {
    this.name= builder.name.trim();
    this.surname = builder.surname.trim();

Will be part of the 0.11.2 release.

@peichhorn peichhorn closed this Jul 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment