title: How do I build a SerialDescriptor for a class when a field has a different serialization mechanism?
body: <p>I have this class (simplified)</p>
  <pre><code>@Serializable(with = MetaAny.Serializr::class)
  class MetaAny constructor(
    val obj: Any,
    val meta: String? = null) {
  
    object Serializr: KSerializer&lt;MetaAny&gt; {
      override val descriptor: SerialDescriptor =
          buildClassSerialDescriptor(&quot;com.travisfw.MetaAny&quot;) {
  //          element(&quot;obj&quot;, isOptional = false, descriptor = ???)
          }
      override fun deserialize(decoder: Decoder): MetaAny {
        TODO(&quot;not implemented&quot;) //function body template
      }
      override fun serialize(encoder: Encoder, value: MetaAny) {
        TODO(&quot;not implemented&quot;) //function body template
      }
    }
  }
  </code></pre>
  <p>MetaAny basically just stores metadata about anything. Other code manages serialization mechanisms that do not enter into the dependencies of this package, and uses MetaAny to just keep arbitrary metadata about the obj field, a serializable object, though not necessarily serializable with kotlinx.serialization. To be explicit here, I will repeat: the <code>val obj</code> will be serialized by other code using a mechanism that this package will not refer to in its dependencies. But I want the serialized <code>obj</code> field to be included in the serialized <code>MetaAny</code>.</p>
  <p>What do I do to make MetaAny serializable with kotlinx.serialization? If it would help, I could require serialization and deserialization functions in the constructor like so:</p>
  <pre><code>class MetaAny&lt;S&gt; constructor(
    val obj: S,
    val encFun: (S) -&gt; okio.ByteString,
    val decFun: (okio.ByteString) -&gt; S,
    val meta: String? = null) {
  </code></pre>
  <p>Or I could require the serialized version of obj be provided in any number of ways.
  …but still, how do I implement the SerialDescriptor of <a href="https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html#kotlinx.serialization%2FKSerializer%2Fdescriptor%2F%23%2FPointingToDeclaration%2F" rel="nofollow noreferrer">KSerializer.descriptor</a>?</p>