I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far:
@Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)")
public void check(final JoinPoint jp) {
LOGGER.debug(jp.getSignature().toLongString());
Object[] args = jp.getArgs();
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof String && ((String) args[i]).isEmpty()) {
args[i] = null;
}
}
}
Unfortunately the overwrite statement args[i] = null;
does now work! Do anyone know how should I overwrite it?
Cheers,
Kevin
AspectJ provides primitive pointcuts that capture join points at these times. These pointcuts use the dynamic types of their objects to pick out join points. They may also be used to expose the objects used for discrimination. this(Type or Id) target(Type or Id)
No doubt about it: AspectJ won't make your programs faster. It adds an additional amount of overhead to your program. Every aspect is a piece of code that has to be executed, consuming time along the way.
Aspect: An aspect is a class that implements enterprise application concerns that cut across multiple classes, such as transaction management. Aspects can be a normal class configured through Spring XML configuration or we can use Spring AspectJ integration to define a class as Aspect using @Aspect annotation.
I believe you have to implement an around advice, instead of a before advice.
Because you can use proceed with your new arguments:
proceed(newArgs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With