byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

How to remove an annotation easily

Open mpet opened this issue 3 years ago • 2 comments

Hi,

I found the following code:

new ByteBuddy() .redefine(clazz) .visit(new MemberRemoval().

image

but no stripAnnotation? Is there any plans for it? I would make my life easier :-)

//mike

mpet avatar Jun 03 '22 05:06 mpet

You are right, this would be a useful feature. I can see if I can add it.

raphw avatar Jun 03 '22 08:06 raphw

Looking at it, I now remember why this is not an option. Annotations are visited by their descriptor and only then it is possible to abort the writing, before paring the entire annotation. Therefore, Byte Buddy normally shortwires annotations, for efficiency reasons.

What you need to do is to configure Byte Buddy to replay annotations: new ByteBuddy().with(AnnotationRetention.DISABLED), and then you can register a Transformer where you change fields or methods to contain certain annotations or not. Then these annotations are written as is.

raphw avatar Jun 03 '22 18:06 raphw