-
Notifications
You must be signed in to change notification settings - Fork 232
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 support for field definition with a predicate #342
Comments
fmbenhassine
changed the title
Add ability to use predicates to define field definition
Add ability to use predicates to define fields
Feb 22, 2019
fmbenhassine
changed the title
Add ability to use predicates to define fields
Add support to define fields using predicates
Feb 22, 2019
fmbenhassine
changed the title
Add support to define fields using predicates
Add support for field definition using predicates
Feb 22, 2019
fmbenhassine
changed the title
Add support for field definition using predicates
Add support for field definition with a predicate
Feb 22, 2019
Good idea. 👍 |
@PascalSchumacher Thank you for your quick feedback! Rebased and merged as 4929f12. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of v3.8, in order to define a field, one should use the
FieldDefinition
API. This API provides 5 methods to define field properties (named
,ofType
,inClass
,isAnnotatedWith
andhasModifiers
).As a library user, this limited set of properties makes it impossible to use a custom condition on a field, for example
field.isSynthetic()
.As a library developer, I will need to update the API each time a user asks to add a custom field property.
A better approach is to use a
Predicate<Field>
as a replacement forFieldDefinition
. Thanks tojava.util.function.Predicate#and
andjava.util.function.Predicate#or
, multiple predicates can be combined to define a field just likeFieldDefinition
, adding the flexibility to define custom conditions without having to change the API each time. Here is an example:Random Beans would provide common predicates and let the user define additional predicates as needed. A first work on this feature can be reviewed in branch
predicates
.@PascalSchumacher WDYT?
BTW, this idea came from a situation where I wanted to exclude all types defined in a given package. I though about adding a TypeDefinition API allowing one to write something like:
But then I found myself exposing all properties of a
Class
. I quickly realized that this was not the best approach.. Hence the idea of using predicates: No need to expose properties + ability to provide custom conditions.The text was updated successfully, but these errors were encountered: