Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explicit inclusion/exlusion of properties #96

Closed
mkarneim opened this issue Mar 11, 2015 · 1 comment
Closed

Support explicit inclusion/exlusion of properties #96

mkarneim opened this issue Mar 11, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@mkarneim
Copy link
Owner

Sometimes you might want to limit the builder to a subset of the pojo's properties.

It would be nice, if we could specify an inclusion and an exclusion pattern, that is used by PojoBuilder to select, which properties are generated into the builder.

The pattern itself should be able to select properties by their name and optionally by their type.

Pattern Syntax

The pattern syntax could look like this:
<name pattern>[:<type pattern>]
where <name pattern> and <type pattern> are used to match the property's name and type.
The pattern syntaxt is some poor-man's regex allowing an asterisk * to match any character,

For example:
*name would select surname, lastname, firstname, but not email.
And
url:java.lang.String would select String url, but not URL url.

Example: Inclusion

@GeneratePojoBuilder(includeProperties = "*name")
public class Contact {
  public String firstname;
  public String surname;
  public String email;
}

This would generate a builder having only firstname and surname as properties.

Example: Exclusion:

@GeneratePojoBuilder(excludeProperties = "*name")
public class Contact {
  public String firstname;
  public String surname;
  public String email;
}

This would generate a builder having only email as property.

Example: Combination of Inclusion and Exclusion:

@GeneratePojoBuilder(includeProperties="*:java.lang.String", excludeProperties = "password")
public class User {
  public String firstname;
  public String surname;
  public String login;
  public String password;
  public String email;
  public String[] notes;
  public URL homepage; 
}

This would generate a builder having only firstname, surname, login, and email as properties, but not password, notes, and homepage.

Limitations

Some limitations are, that only properties can be excluded, that are not part of the constructor or factory method arguments.

@mkarneim mkarneim self-assigned this Mar 11, 2015
@mkarneim
Copy link
Owner Author

I forgot to mention that the annotation attributes includeProperties and excludeProperties should be of type String[].

This allows to specify a set of inclusion / exclusion patterns.

@mkarneim mkarneim added this to the 3.4.0 milestone Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant