Is there a more kotlin-y way of doing this. In thi...
# jackson-kotlin
h
Is there a more kotlin-y way of doing this. In this instance JsonDataClassHolder is an interface, which many different types can implement.
Copy code
fun <T : JsonDataClassHolder> findProfile(
        content: String,
        clazz: Class<T>
    ): T {
  return mapper.readValue(contentRaw, clazz)
}
I also tried
Copy code
fun <T : JsonDataClassHolder> findProfile(
        content: String
    ): T {
  val type = object : TypeReference<T>() {}
  return mapper.readValue(contentRaw, type)
}
but got the following error:
Copy code
Cannot construct instance of `JsonDataClassHolder` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
An example of how I'd like to call this function might be:
Copy code
private data class CoolJson(
            val status: String
        ) : JsonDataClassHolder

findProfile<CoolJson>("""{'status': 'cool'""")
}
I liked how I only needed to pass the type as a type parameter versus in my working example as a function variable. I guess the kotlin way would be to make the reified inline, but i would like to avoid that as well in this case.