title: Polymorphic kotlinx serialization for complex hierarchy
body: <p>With polymorphic serialization, I want to serialize classes A, B1, B2. I want to get the following line with class B2</p>
  
  <pre><code>{"type":"type_2","baseField":"base_field_B","fieldB":true,"fieldB2":"field_B_2"}
  </code></pre>
  
  <p>I use hierarchy like</p>
  
  <pre><code>interface BaseClass {
      val baseField: String
  }
  
  @Serializable
  @SerialName("type_1")
  data class A(
      override val baseField: String,
      val fieldA: Int
  ) : BaseClass
  
  @Serializable
  @SerialName("type_2")
  abstract class B: BaseClass{
      abstract override val baseField: String
      abstract val fieldB: Boolean
  }
  
  @Serializable
  data class B1(
      override val baseField: String,
      override val fieldB: Boolean,
      val fieldB1: Float
  ) : B()
  
  @Serializable
  data class B2(
      override val baseField: String,
      override val fieldB: Boolean,
      val fieldB2: String
  ) : B()
  </code></pre>
  
  <p>and doing serialization like this</p>
  
  <pre><code>Json(context = SerializersModule {
      polymorphic(BaseClass::class) {
          A::class with A.serializer()
          B::class with B.serializer()
      }
  }).stringify(
      PolymorphicSerializer(BaseClass::class),
      B1("base_field_B", true, "field_B_2")
  )
  </code></pre>
  
  <p>As a result, I get <code>kotlinx.serialization.SerializationException: class B2 (Kotlin reflection is not available) is not registered for polymorphic serialization in the scope of interface BaseClass (Kotlin reflection is not available)</code></p>
  
  <p>How do I serialize a given structure correctly? Classes B1, B2 must be serialized with type "type_2".</p>