javajsonspring-bootaopaspect

Put some variable in json response inside Aspect


We want to add some variabale in json response, but inside aspect.

we need to do something similar to what is done in this function but instead of with the request it would be with the response.


Solution

  • you want exact impl or just the direction? if the direction, then annotate your method with custom annotation to get rid of patterns and do something like this:

    @Around("@annotation(FQAnnotationName)")
    public Map<String, Object> aroundSomething(ProceedingJointPoint jointPoint){
       Map<String, Object> resultOfMethodExecution = (Map<String, Object>) jointPoint.proceed();  
       //do something with the result returned
       return resultOfMethodExecution;
    }
    

    Here @Around is used to wrap invocation within your aspect. Typecast the result of target method, modify it in the way you want and return.

    This is just an approximated solution, do not judge it as an exact implementation of what you need.