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

Add Annotation to exclude Properties #118

Open
Adrodoc opened this issue Aug 3, 2016 · 3 comments
Open

Add Annotation to exclude Properties #118

Adrodoc opened this issue Aug 3, 2016 · 3 comments

Comments

@Adrodoc
Copy link
Contributor

Adrodoc commented Aug 3, 2016

While it is cool to be able to exclude properties in the main Annotation (especially with wildcards), it would often be more convenient, if there was an exclude Annotation to put on fields or setter methods.
It could be named something like @ExcludeProperty, @ExcludePojoBuilderProperty or @ExcludeFromPojoBuilder and should add exclusions exactly as if they were specified in GeneratePojoBuilder.excludeProperties. An appropriate include Annotation would be cool too.

@mkarneim
Copy link
Owner

mkarneim commented Aug 7, 2016

I appreciate this, although we need to decide how to handle conflicting directives by defining some kind of precedence.

Just to make it clear:

  • The @GeneratePojoBuilder annotation can be placed on multiple locations, e.g. on several constructors of the pojo and on several factory methods simultaneously. Each of those annotations can include and exclude properties. Luckily they do not conflict since for each occurence a separate builder will be generated.
  • Field and method annotations (e.g. @ExcludeFromPojoBuilder) can be placed on fields and methods in the whole class hierarchy. They would be interpreted during all @GeneratePojoBuilder executions (see above) but not always treated in the same way.
  • Also It can be irritating if a field is marked as 'included' and the setter method is marked as 'excluded'.
  • We must also take care of overridden setter methods with conflicting annotations.
  • Perhaps it is easier if there is no @IncludeInPojoBuilder annotation at all.

Suggestions?

@Adrodoc
Copy link
Contributor Author

Adrodoc commented Aug 7, 2016

As for inheritance i'd say that the concrete class always wins over the super class. If the Setter of a super class and the Setter of an Interface are inherited and have a conflict, I suggest to handle it similar to default implementations in interfaces where you have to override the method and decide what to do in your own implementation.
Conflicts should be easy to detect, because you build a map for each key anyway where you go over most possible places for such an Annotation.
Originally I thought that conflicts should just be handled like a conflict in the main Annotation: @GeneratePojoBuilder(includeProperties="value",excludeProperties="value"), but now I think that a compiler error is appropriate (I don't actually know how above conflict is handled). There is an argument to be made for exclude to have precedence, but that is probably to confusing. Note that you can even create a conflict without a Setter method by annotating the field twice.
When I opened this issue I didn't think of inheritance wich makes this more complicated.

@drekbour
Copy link
Contributor

drekbour commented Mar 4, 2019

@mkarneim Feels like this discussion has ended and the request doesn't add value (without adding notable complexity to the end user)?

I'm going through your issues to see what I might be able to help with, there's a lot of noise in here that needs triaging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants