I've searched everywhere for this but the only solutions I've found relate to getting the values of the annoation, and not the parameter that is annotated.
I have an aspect that intercepts any methods annotated with a custom annotation, i.e.
@EnabledAudit(activity = CUSTOMER-SEARCH)
public void customerSearch(@ParamToLog(value="objectId" Long objectId)
My aspect is something like so
@Around("(@annotation(EnabledAudit))")
public Object profileAllMethods(ProceedingJoinPoint proceedingJoinPoint)
What I am interested in is the parameter annotated with @ParamToLog. It's easy enough to get this annotation using like so
(MethodSignature) proceedingJoinPoint.getSignature().getMethod().getParameterAnnotations()
and then just to check if it's present. But all this will give me is the constant value defined at compile time. What I actually want is the value of the Long objectId that is annotated with @ParamToLog.
I can get the actual values using the joinpoint signature and couple these with the parameter names to cross reference.
Object[] signatureArgs = methodSignature.getArgs();
String[] paramNames = methodSignature.getParameterNames()
It's easy enough then to work out which value goes with which parameter name by simply matching index positions.
However I cannot figure out how to work out which of these is annotated with @ParamToLog.
At the moment best I can think of is to use the parameter name in the @ParamLog("paramName"), retrieve this using the getParameterAnnotations(..) and then using this value to find the correct arg from the args[].
But this is not safe and open to user error, a simple spelling mistake in the annoation value and the match will fail so nothing to log against.
Any ideas on how to figure out what parameter an annoation is associated with really welcome. Wondering if I am missing something really obvious. Can't believe that something so relevant would not be easily done.
Thanks