add an Annotation to javassist dynamic Proxy with ProxyFactory

39 Views Asked by At

In ByteBuddy when I create a dynamic proxy for MyBaseClass I can easily add annotations to it:

final var proxyClassBuilder = new ByteBuddy()
    .subclass(MyBaseClass.class)
    // other stuff here...
    .annotateType(new MyAnnotation() {
        public String value() { return "value of MyAnnotation"; }
        public Class<? extends Annotation> annotationType() { return MyAnnotation.class; }
    });
final var proxyClass = proxyClassBuilder.make().load(...).getLoaded();

Is it possible to do something similar using ProxyFactory? Like something along the lines of the below, except that addAnnotation(...) method does not exist currently:

final var proxyClassBuilder = new ProxyFactory();
proxyClassBuilder.setSuperclass(MyBaseClass.class);
// other stuff here...
proxyClassBuilder.addAnnotation(new MyAnnotation() {  // missing feature?
    public String value() { return "value of MyAnnotation"; }
    public Class<? extends Annotation> annotationType() { return MyAnnotation.class; }
});
final var proxyClass = proxyClassBuilder.createClass();

Is there a way to workaround this "missing feature" and somehow add annotations to created classes?

0

There are 0 best solutions below