https://kotlinlang.org logo
y

Yao-Wen Mei

07/06/2022, 9:40 PM
Hello, a question on use
@SerialInfo
annotation on Java annotations: we have a Kotlin library which is depend on our Java library and use some of the Java annotations. I want to use some of the Java annotations during Kotlin serialization process. In order to do this, I have to 1) add
@SerialInfo
on the Java annotations, and 2) define an inner class
Impl
inside of my Java annotation for the Kotlin complier plugin. The working code is like below:
Copy code
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
@SerialInfo  //<--------------------------------------------------------- Add this line
@kotlin.annotation.Target(allowedTargets = AnnotationTarget.PROPERTY)
public @interface ServerTimestamp {

  final class Impl implements ServerTimestamp { // <--------------------- Add this block
    @Override
    public Class<? extends Annotation> annotationType() {
      return (Class<? extends Annotation>) ServerTimestamp.class;
    }
  }
}
My question is will the complier plugin always looking for the
Impl
inner class in the future? How stable this mechanism is going to be? Thank you~
e

ephemient

07/06/2022, 11:09 PM
I expect it should be stable since future compiler plugin versions should still work with libraries compiled in the past. but since you're not using the compiler plugin itself but are trying to reproduce its effects, I don't think it can be guaranteed that you haven't missed anything that it might additionally depend on in the future