Hey y’all. I’m trying to get into bytecode transfo...
# getting-started
m
Hey y’all. I’m trying to get into bytecode transformation with Kotlin, but my efforts are thwarted by an issue with annotation retention that I can’t seem to get past. In the attached image, you can see that I define a custom field annotation with binary retention on the left. I apply this annotation to some random fields of my sample class (middle), but it doesn’t make it into the actual class file (right). Changing retention and target of the annotation class have not done anything, and neither has trying to scope the annotation at the use site with
@field:Redacted
or
@property:Redacted
. For testing, I tried adding another third-party annotation to one of the fields and that one does end up in the class file, so I’m not sure what I’m doing wrong. Does anybody have a pointer regarding how to make my annotation show up in
User.class
? Thanks in advance.
Update: It seems like it was the target after all. For my specific usage, it must be
AnnotationTarget.VALUE_PARAMETER
.
FIELD
isn’t cutting it here.
h
can you please paste the code so i can try to help you
m
No need, I was able to resolve it already – but thank you nonetheless! The solution is to change
Copy code
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.FIELD)
annotation class Redacted
to
Copy code
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER)
annotation class Redacted
and it is put in the class file. 🙂