title: Kotlinx Serialization: How to circumvent reified typeargs for deserialization?
body: <p>Actually, the main problem is still that there are no reified typeargs for classes in Kotlin. But here is why this bothers me in this specific case:</p>
  <p>Suppose you have a wrapper class <code>Wrapper</code> that takes in a string <code>content</code> and a class* <code>type</code> and can output an object of class <code>type</code> retrieved by parsing <code>content</code> as JSON by demand by calling the function <code>getObj()</code>:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Wrapper&lt;T&gt;(private val content: String, /*private val type: KClass&lt;*&gt;*/) {
      fun getObj(): T {
          // ?
      }
  }
  </code></pre>
  <p>And I want to use kotlinx.serialization. Now, you might have noticed how I put an asterisk after &quot;class&quot; before. Here's the reason: Yes, <code>Wrapper</code> has to take the target class in <em>some</em> way, but how? Should it be just the typearg (won't work because type erausre) or a <code>KClass</code> reference (won't work because I need a reified typearg)?</p>
  <p>The thing is that as far as I know, the only way to decode a generic JSON to a serializable target class is to use <code>Json.decodeFromString&lt;T&gt;(content)</code>, where <code>T</code> is the target type and <code>content</code> is the JSON string. Now, <code>T</code> is defined to be reified (so that the type can be processed at runtime) and can only be filled with another reified typearg or an actual class reference. I can't use another reified typearg because I am in the context of a class and a class cannot have reified typeargs. I can also not use an actual class reference because the user of the class should be able to construct it with different targets, e.g. they decide what the target is, not me.</p>
  <p>So, how do I do this with kotlinx.serialization? Is it even possible?</p>