Trying to weave in a default toString() method for a large number of DTOs, using compile-time weaving only. The goal is to return a JSON representation using the Jackson lib
I tried your scenario and could replicate the behavior, I also tried combinations of @DeclareMixin
instead of @DeclareParent
and could not get that to work either. What worked for me though is to use native aspectj this way:
public aspect JsonToStringAspect {
private interface JsonToString {}
declare parents: com.mycompany.dto.* implements JsonToString;
public String JsonToString.toString() {
return "Overridden String through JsonToStringAspect";
}
}
I am guessing that this may not be feasible using @AspectJ
and may be possible only through native aspects.