One Solution
This example is about using annotations so we will go with the 6th option. First, here’s what adding a field that we want to ignore might look like:
Notice that the setter and the getter are normal. The only change is the addition of an annotation to the field called “ignoredField”.
Here’s the annotation @IgnoreField:
Of course, to make this change happen, we actually need to update our pointcut. When we want to refer to annotations, we use the @ to indicate an annotation in a pointcut. Here’s an updated version of FieldSetAspect:
The first pointcut, trackedObject, picks out all fields defined in the TrackedObjectMixin class. As mentioned elsewhere, this avoids infinite recursion.
The second pointcut, allFields, includes the new syntax. Notice the first part of the set:
@annotation.IgnoreField is the fully-qualified name of the annotation. ! means not. Read this as “the setting of any fields that do NOT have the annotation IgnoreField on them.”
Comments