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

[FEATURE] @FieldNameConstants.Include must be added in a enum for all fields #3756

Open
Gaboxondo opened this issue Sep 26, 2024 · 1 comment

Comments

@Gaboxondo
Copy link

Gaboxondo commented Sep 26, 2024

Right now, for using Enums within annotation like the Spring boot cache ones, you can't unless you declare the enum field.
This right now can be done with the combination of @FieldNameConstnats and @FieldNameConstants.Include

example of usage of this annotation in an Enum

@CacheEvict(value = Colors.Fields.Red)

and there are also a lot of cases for using enums within some other annotations

The problem is that in a Enum you cannot use just one annotation at the class level for creating the fields to ALL the enum values.
You have to annotate the class with the @FieldNameConstnats and each param with @FieldNameConstants.Include.

@FieldNameConstants
public class CacheNames {
  @FieldNameConstants.INCLUDE
  ColorsCache,
  @FieldNameConstants.INCLUDE
  TShirstCache,
  @FieldNameConstants.INCLUDE
  CountriesCache;
}

it will be easier to be able to do something like this:

@FieldNameConstants
public class Colors {
 ColorsCache,
 TShirstCache,
 CountriesCache;
}

and just use the exclusion when needed.

This will benefit all people developers of java that are using this type of annotations with enums.
In the previous example the enum only had 3 fields but imagine an enum with 20 having to add all of this field-by-field annotation.

Thanks a lot

@uapcent
Copy link

uapcent commented Sep 26, 2024

That would definitely help me with my current project. I had to add the annotations too many times, i was surprised there wasn't a cleaner way.

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

No branches or pull requests

2 participants