# getting-started


02/04/2022, 3:42 AM
Hey everyone 👋 I am trying to create a gson type adapter to process the object after it is de-serialized, following the pattern described here, However, not getting the right approach to convert that impl to Kotlin . Specifically, using generic type on an interface and apply the interface to an annotation class. Could someone provide any ideas or hint to get this approach right. This is what I have got so far,
Problem that I am running into is that I cant use a type for my interface which is passed as an argument to the annotation class so I tried to use
Copy code
annotation class EmptyObjectValidator(val deserializer: KClass<out JsonPostDeserializer<*>>)
^ this enables me to use the concrete impl for any class with annotation, e.g
Copy code
data class Fluff(val blah: String = "")
and this is how the concrete impl might look like,
Copy code
class FluffValidator: JsonPostDeserializer<Fluff> {
    override fun postDeserialize(type: Fluff) {
        TODO("Not yet implemented")
However, use of
projection type doesn’t allow me to call the interface method when called like this,
Copy code
val objectValidator = type.rawType.getAnnotation( ?: return null
override fun read(`in`: JsonReader?): T {
    val result =`in`)
    val postDeserializer: JsonPostDeserializer<*> = objectValidator.deserializer.javaObjectType.newInstance()

    return result
it errors out when calling the method here


02/04/2022, 6:00 AM
on one hand, you can
Copy code
annotation class EmptyObjectValidator<T>(val deserializer: KClass<out JsonPostDeserializer<T>>)
instead of using a raw type in the annotation, but regardless I think your caller will need to perform an unchecked cast since
won't understand the generic there
👍 1