title: Is there a way to use Kotlinx serialisation in an Android savedInstanceState Bundle?
body: <p>It looks like the compiler doesn't want to use Kotlinx serialized classes in <code>putSerializable</code> and <code>getSerializable</code>.
  It says <code>Type mismatch: inferred type is MyViewModel.SavedState but Serializable? was expected</code>.</p>
  
  <p>In my Activity:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      AndroidInjection.inject(this)
      super.onCreate(savedInstanceState)
  
      setContentView(R.layout.my_activity_layout)
  
      viewModel.init(savedInstanceState?.getSerializable(SAVE_STATE) as? SavedState) // compiler complains here
  }
  
  override fun onSaveInstanceState(outState: Bundle) {
      super.onSaveInstanceState(outState)
      outState.putSerializable(SAVE_STATE, viewModel.buildSaveState()) // and here
  }
  </code></pre>
  
  <p>In my ViewModel:</p>
  
  <pre><code>fun buildSaveState(): SavedState =
          SavedState(value1, value2, value3, value4)
  
  @Serializable
  data class SavedState(val foo: Boolean?,
                        val foo1: Enum1?,
                        val foo2: Enum2?,
                        val foo3: MyType?)
  </code></pre>
  
  <p>MyType:</p>
  
  <pre><code>@Serializable
  sealed class MyType {
      data class MyType1(val foo4: Enum3) : MyType()
      data class MyType2(val foo5: Enum4) : MyType()
  
      enum class Enum3 {
          ...
      }
  
      enum class Enum4 {
          ...
      }
  }
  </code></pre>