Skc
02/04/2022, 3:42 AM*
projection
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class EmptyObjectValidator(val deserializer: KClass<out JsonPostDeserializer<*>>)
^ this enables me to use the concrete impl for any class with annotation, e.g
@EmptyObjectValidator(FluffValidator::class)
data class Fluff(val blah: String = "")
and this is how the concrete impl might look like,
class FluffValidator: JsonPostDeserializer<Fluff> {
override fun postDeserialize(type: Fluff) {
TODO("Not yet implemented")
}
}
*
projection type doesn’t allow me to call the interface method when called like this,
val objectValidator = type.rawType.getAnnotation(EmptyObjectValidator::class.java) ?: return null
override fun read(`in`: JsonReader?): T {
val result = delegate.read(`in`)
val postDeserializer: JsonPostDeserializer<*> = objectValidator.deserializer.javaObjectType.newInstance()
postDeserializer.postDeserialize(result)
return result
}
it errors out when calling the method here
postDeserializer.postDeserialize(result)
ephemient
02/04/2022, 6:00 AMannotation class EmptyObjectValidator<T>(val deserializer: KClass<out JsonPostDeserializer<T>>)
@EmptyObjectValidator<Fluff>(FluffValidator::class)
instead of using a raw type in the annotation, but regardless I think your caller will need to perform an unchecked cast since .getAnnotation
won't understand the generic there