title: kotlinx.serialization.cbor.CborDecodingException: Expected start of map, but found 78
body: <p>I was trying to use one of the Kotlin's <a href="https://github.com/Kotlin/kotlinx.serialization" rel="nofollow noreferrer">serialization package</a> with the following custom example class. I will extend this class matching the real use case by adding a <code>List</code> of the real class (which also need to be serialized), but right now the problem simply lies in de-serialization.
  I've managed to make the serialization works (in the second snippet of code there's both the object to be serialized and the resulting <code>String</code>) and <em>seems</em> that the de-serialization process requires to be done in the same way (i.e., by using an instance of <code>NullableSerializer</code>) (in fact, I haven't found a simple and correct way to de-serialize an encoded object right now.
  Here's the class, simple but wannabe-complex.</p>
  
  <pre><code>@Serializable(with = EhEH.Companion::class)
  data class EhEH(
      val i: Int
      , val txt: String
      //, val list: Array&lt;String&gt; // next feature, also with complex data, not only "simple" Strings
  ) {
  
      @Serializer(forClass = EhEH::class)
      companion object : KSerializer&lt;EhEH&gt; {
          public var deserialEhEH: DeserializationStrategy&lt;EhEH&gt; = EhEH
  
  
          override val descriptor: SerialDescriptor =
              SerialDescriptor("EhEHSerializer", PrimitiveKind.STRING)
  
          override fun serialize(encoder: Encoder, obj: EhEH) =
              encoder.encodeString(obj::class.qualifiedName!!)
  
          override fun deserialize(decoder: Decoder): EhEH {
              val dec = decoder.beginStructure(descriptor)
              var txt: String? = null
              var x: Int? = null
              var i = -1
              var notFinished = true
              do {
                  i = dec.decodeElementIndex(descriptor)
                  when (i) {
                      CompositeDecoder.READ_DONE -&gt; notFinished = false
                      0 -&gt; x = dec.decodeStringElement(descriptor, i).toIntOrNull()
                      1 -&gt; txt = dec.decodeStringElement(descriptor, i)
                      else -&gt; throw SerializationException("Unknown index $i")
                  }
              } while (notFinished)
              dec.endStructure(descriptor)
              return EhEH(
                  x ?: throw MissingFieldException("x"),
                  txt ?: throw MissingFieldException("txt")
              )
          }
  
      }
  
      override fun toString(): String {
          return "EhEH(i=$i, s='$txt')"
      }
  }
  </code></pre>
  
  <p>The manual-test function (whose value is simply printed) is:</p>
  
  <pre><code>@InternalSerializationApi
      fun testCborString(): String {
          var e: EhEH = EhEH(
              7,
              "poreccio"
              //, listOf("just", "another", "vacuum", "test")
          )
          return Cbor.dumps(
              NullableSerializer(
                  EhEH.Companion
              ), e
          ) + " &lt;-&gt; " + (
                  {
                      (Cbor.load(
                          NullableSerializer(
                              EhEH.Companion
                          ),
                          Cbor.dump(
                              NullableSerializer(EhEH.Companion), e
                          )
                          //the dumped value should be "781d62632e7472797669756d2e6170692e726573706f6e7365732e45684548"
                      )
                              as EhEH).toString()
                  } as () -&gt; String)()
      }
  </code></pre>
  
  <p>When I try to run it, the exception lies in the <code>Cbor.load</code> call and is:</p>
  
  <pre><code>kotlinx.serialization.cbor.CborDecodingException: Expected start of map, but found 78
  </code></pre>
  
  <p>Am I the only one in WHOLE internet having this problem?</p>