title: Kotlin and Jackson - Missing type id when trying to resolve subtype of simple type
body: <p>I have a Kotlin sealed class - <code>Pet</code> and two subclasses - <code>Dog</code> and <code>Cat</code>. My application requires to transfer a collection of pets serialized in JSON. In order to differentiate subclasses I use Jackson <code>@JsonTypeInfo</code> and <code>@JsonSubTypes</code> annotations. The listing below:</p>
  <pre><code>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = &quot;type&quot;)
  @JsonSubTypes(
      JsonSubTypes.Type(value = Dog::class, name = &quot;dog&quot;),
      JsonSubTypes.Type(value = Cat::class, name = &quot;cat&quot;)
  )
  sealed class Pet { abstract val name: String }
  
  data class Dog(override val name: String): Pet()
  data class Cat(override val name: String): Pet()
  </code></pre>
  <p>Single instances are serialized and deserialized properly:</p>
  <pre><code>    @Test
      fun `serialize dog`() {
          val dog = Dog(&quot;Kevin&quot;)
          val dogJson = objectMapper.writeValueAsString(dog)
  
          JsonAssert.assertEquals(dogJson, &quot;&quot;&quot;{&quot;type&quot;:&quot;dog&quot;,&quot;name&quot;:&quot;Kevin&quot;}&quot;&quot;&quot;)
          val newDog = objectMapper.readValue&lt;Dog&gt;(dogJson)
      }
  </code></pre>
  <p>The problem comes up when a collection of pets is being serialized and deserialized:</p>
  <pre><code>    @Test
      fun `serialize dog and cat`() {
          val pets: Set&lt;Pet&gt; = setOf(Dog(&quot;Kevin&quot;), Cat(&quot;Marta&quot;))
          val petsJson = objectMapper.writeValueAsString(pets)
  
          JsonAssert.assertEquals(petsJson, &quot;&quot;&quot;[{&quot;name&quot;:&quot;Kevin&quot;},{&quot;name&quot;:&quot;Marta&quot;}]&quot;&quot;&quot;)
          val newPets = objectMapper.readValue&lt;Set&lt;Pet&gt;&gt;(petsJson)
      }
  </code></pre>
  <p>Jackson swallows the type property during serialization and because of that <code>objectMapper</code> is not able to <code>readValue</code>:</p>
  <pre><code>com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class s3.moria.workflows.common.model.Pet]: missing type id property 'type'
   at [Source: (String)&quot;[{&quot;name&quot;:&quot;Kevin&quot;},{&quot;name&quot;:&quot;Marta&quot;}]&quot;; line: 1, column: 17] (through reference chain: java.util.HashSet[0])
  </code></pre>
  <p>Any ideas how tackle this problem? Or workarounds?</p>
  <p>Jackson version: 2.9.0</p>